Skip to content

Commit daea610

Browse files
authored
Merge pull request khonsulabs#286 from ModProg/key-lifetime
Lifetime for `#[derive(Key)]`
2 parents 0884359 + 979fdb3 commit daea610

File tree

12 files changed

+137
-123
lines changed

12 files changed

+137
-123
lines changed

crates/bonsaidb-macros/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ rust-version = "1.65"
1616
proc-macro = true
1717

1818
[dependencies]
19-
attribute-derive = "0.3.1"
19+
attribute-derive = "0.6.0"
2020
proc-macro-crate = "1.1.0"
2121
proc-macro-error = "1"
2222
proc-macro2 = { version = "1.0.37", features = ["nightly"] }
2323
quote = "1"
24-
quote-use = { version = "0.6.0", features = ["namespace_idents"] }
25-
syn = "1"
24+
quote-use = { version = "0.7.0", features = ["namespace_idents"] }
25+
syn = "2"
2626
trybuild = "1.0.54"
2727

2828
[dev-dependencies]

crates/bonsaidb-macros/src/lib.rs

Lines changed: 96 additions & 112 deletions
Large diffs are not rendered by default.

crates/bonsaidb-macros/tests/key.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use bonsaidb::core::key::{Key, KeyEncoding};
24

35
#[test]
@@ -125,3 +127,17 @@ fn enum_u64() {
125127
&[255, 255, 255, 255, 255, 255, 255, 255]
126128
);
127129
}
130+
131+
#[test]
132+
fn lifetime() {
133+
#[derive(Clone, Debug, Key)]
134+
struct Test<'a, 'b>(Cow<'a, str>, Cow<'b, str>);
135+
136+
assert_eq!(
137+
&[97, 0, 98, 0, 1, 1],
138+
Test("a".into(), "b".into())
139+
.as_ord_bytes()
140+
.unwrap()
141+
.as_ref()
142+
)
143+
}

crates/bonsaidb-macros/tests/ui/collection/invalid_attribute.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: expected identifier
44
4 | #[collection(name = "hi", authority = "hello", "hi")]
55
| ^^^^
66

7-
error: Only `authority = \"some-authority\"`, `name = \"some-name\"`, `views = [SomeView, AnotherView]`, `primary_key = u64`, `natural_id = |contents: &Self| Some(contents.id)`, serialization = SerializationFormat` and `core = bonsaidb::core` are supported attributes
7+
error: supported fields are `authority`, `name`, `views`, `serialization`, `encryption_key`, `encryption_required`, `encryption_optional`, `primary_key`, `natural_id` and `core`
88
--> tests/ui/collection/invalid_attribute.rs:8:48
99
|
1010
8 | #[collection(name = "hi", authority = "hello", field = 200)]

crates/bonsaidb-macros/tests/ui/collection/missing_name.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
error: You need to specify the collection name via `#[collection(name = \"name\")]`
1+
error: required `name` is not specified
2+
3+
= help: try `#[collection(name="name")]`
24
--> tests/ui/collection/missing_name.rs:3:10
35
|
46
3 | #[derive(Collection)]

crates/bonsaidb-macros/tests/ui/schema/invalid_attribute.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: expected identifier
44
5 | #[schema(name = "name", "hi")]
55
| ^^^^
66

7-
error: Only `name = \"name\"`, `authority = \"authority\"`, `collections = [SomeCollection, AnotherCollection]`, `include = [OtherSchema]`, and `core = bonsaidb::core` are supported attributes
7+
error: supported fields are `name`, `authority`, `collections`, `include` and `core`
88
--> tests/ui/schema/invalid_attribute.rs:9:25
99
|
1010
9 | #[schema(name = "name", test = "hi")]

crates/bonsaidb-macros/tests/ui/schema/missing_name.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
error: You need to specify the schema name via `#[schema(name = \"name\")]`
1+
error: required `name` is not specified
2+
3+
= help: try `#[schema(name="name")]`
24
--> tests/ui/schema/missing_name.rs:3:10
35
|
46
3 | #[derive(Schema)]

crates/bonsaidb-macros/tests/ui/view/invalid_attribute.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: expected identifier
44
4 | #[view(name = "hi", "hi")]
55
| ^^^^
66

7-
error: Only `collection = CollectionType`, `key = KeyType`, `name = \"by-name\"`, `value = ValueType` and `serialization = SerializationFormat` and `core = bonsaidb::core` are supported attributes
7+
error: supported fields are `collection`, `key`, `name`, `value`, `core` and `serialization`
88
--> tests/ui/view/invalid_attribute.rs:8:21
99
|
1010
8 | #[view(name = "hi", authority = "hello", "hi")]

crates/bonsaidb-macros/tests/ui/view/missing_collection.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
error: You need to specify the collection type via `#[view(collection = CollectionType)]`
1+
error: required `collection` is not specified
2+
3+
= help: try `#[view(collection=CollectionType)]`
24
--> tests/ui/view/missing_collection.rs:3:10
35
|
46
3 | #[derive(View)]

crates/bonsaidb-macros/tests/ui/view/missing_key.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
error: You need to specify the key type via `#[view(key = KeyType)]`
1+
error: required `key` is not specified
2+
3+
= help: try `#[view(key=KeyType)]`
24
--> tests/ui/view/missing_key.rs:3:10
35
|
46
3 | #[derive(View)]

0 commit comments

Comments
 (0)