Skip to content

Commit eedf4ec

Browse files
author
Bennett Hardwick
committed
Fix doctests
1 parent ef6c2aa commit eedf4ec

13 files changed

+127
-76
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ version = "0.1.0"
44
edition = "2021"
55

66
[lib]
7-
# Disable for now
8-
doctest = false
9-
107
# Starting in Rust 1.62 you can use `cargo add` to add dependencies
118
# to your project.
129
#

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,25 @@ See below for more information on schema design for Cryptonamo tables.
7676

7777
#### Annotating a Cryptanomo Type
7878

79-
To use Cryptonamo, you must first annotate a struct with the `Cryptonamo` derive macro.
79+
To use Cryptonamo, you must first annotate a struct with the the derive macros for the Cryptonamo traits you wish to implement.
8080

8181
```rust
82-
use cryptonamo::Cryptonamo;
82+
use cryptonamo::{Encryptable, Decryptable, Searchable};
8383

84-
#[derive(Cryptonamo)]
85-
#[cryptonamo(partition_key = "email")]
84+
#[derive(Debug, Encryptable, Decryptable, Searchable)]
8685
struct User {
8786
name: String,
87+
88+
#[partition_key]
8889
email: String,
8990
}
9091
```
9192

92-
The `Cryptonamo` derive macro will generate implementations of the following traits:
93+
This example implements the traits:
9394

94-
* `Cryptonamo` - a top-level trait that sets up the table name and partition key
95-
* `DecryptedRecord` - a trait that allows you to decrypt a record from DynamoDB
96-
* `EncryptedRecord` - a trait that allows you to encrypt a record for storage in DynamoDB
97-
* `SearchableRecord` - a trait that allows you to search for records in DynamoDB
95+
* `Decryptable` - a trait that allows you to decrypt the record from DynamoDB
96+
* `Encryptable` - a trait that allows you to encrypt the record for storage in DynamoDB
97+
* `Searchable` - a trait that allows you to search for records in DynamoDB
9898

9999
The above example is the minimum required to use Cryptonamo however you can expand capabilities via several macros.
100100

@@ -107,8 +107,8 @@ To store a field as a plaintext, use the `plaintext` attribute:
107107
use cryptonamo::Cryptonamo;
108108

109109
#[derive(Cryptonamo)]
110-
#[cryptonamo(partition_key = "email")]
111110
struct User {
111+
#[partition_key]
112112
email: String,
113113
name: String,
114114

@@ -133,8 +133,8 @@ If you don't want a field stored in the the database at all, you can annotate th
133133
use cryptonamo::Cryptonamo;
134134

135135
#[derive(Cryptonamo)]
136-
#[cryptonamo(partition_key = "email")]
137136
struct User {
137+
#[partition_key]
138138
email: String,
139139
name: String,
140140

@@ -174,9 +174,9 @@ To index a field, use the `query` attribute:
174174
use cryptonamo::Cryptonamo;
175175

176176
#[derive(Cryptonamo)]
177-
#[cryptonamo(partition_key = "email")]
178177
struct User {
179178
#[cryptonamo(query = "exact")]
179+
#[partition_key]
180180
email: String,
181181

182182
#[cryptonamo(query = "prefix")]
@@ -191,9 +191,9 @@ All indexes with the same compound name are combined into a single index.
191191
use cryptonamo::Cryptonamo;
192192

193193
#[derive(Cryptonamo)]
194-
#[cryptonamo(partition_key = "email")]
195194
struct User {
196195
#[cryptonamo(query = "exact", compound = "email#name")]
196+
#[partition_key]
197197
email: String,
198198

199199
#[cryptonamo(query = "prefix", compound = "email#name")]
@@ -292,9 +292,9 @@ For example, you might want to store related records to `User` such as `License`
292292
use cryptonamo::Cryptonamo;
293293

294294
#[derive(Cryptonamo)]
295-
#[cryptonamo(partition_key = "user_email")]
296295
struct License {
297296
#[cryptonamo(query = "exact")]
297+
#[partition_key]
298298
user_email: String,
299299

300300
#[cryptonamo(plaintext)]
@@ -312,9 +312,9 @@ For example, you might want to query users by name using a prefix (say for using
312312

313313
```rust
314314
#[derive(Cryptonamo)]
315-
#[cryptonamo(partition_key = "email")]
316315
pub struct UserView {
317316
#[cryptonamo(skip)]
317+
#[partition_key]
318318
email: String,
319319

320320
#[cryptonamo(query = "prefix")]

examples/common/license.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use cryptonamo::{Decryptable, Encryptable, Searchable};
22

33
#[derive(Debug, Encryptable, Decryptable, Searchable)]
4-
#[cryptonamo(partition_key = "email")]
54
pub struct License {
5+
#[partition_key]
66
email: String,
77
number: String,
88
expires: String,

examples/common/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use cryptonamo::{Decryptable, Encryptable, Searchable};
22

33
#[derive(Debug, Encryptable, Decryptable, Searchable)]
4-
#[cryptonamo(partition_key = "email")]
54
#[cryptonamo(sort_key_prefix = "user")]
65
pub struct User {
76
#[cryptonamo(query = "exact", compound = "email#name")]
87
#[cryptonamo(query = "exact")]
8+
#[partition_key]
99
pub email: String,
1010

1111
#[cryptonamo(query = "prefix", compound = "email#name")]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cryptonamo::{Decryptable, Encryptable, Searchable};
22

33
#[derive(Debug, Encryptable, Decryptable, Searchable)]
4-
#[cryptonamo(partition_key = "name")]
54
pub struct UserResultByName {
5+
#[partition_key]
66
pub name: String,
77
}

src/encrypted_table/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ impl EncryptedTable {
142142
}
143143
}
144144

145-
// TODO: create PrimaryKey abstraction
146-
pub async fn delete<E: Searchable>(&self, k: impl Into<E::PrimaryKey>) -> Result<(), DeleteError> {
145+
pub async fn delete<E: Searchable>(
146+
&self,
147+
k: impl Into<E::PrimaryKey>,
148+
) -> Result<(), DeleteError> {
147149
let PrimaryKeyParts { pk, sk } = k.into().into_parts(E::type_name());
148150

149151
let pk = AttributeValue::S(encrypt_partition_key(&pk, &self.cipher)?);

0 commit comments

Comments
 (0)