mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-08 22:28:01 -05:00
chore(versionable): add '#[versionize(dispatch = T)]' in macro
This allows to add new attributes without arguments to the proc-macro
This commit is contained in:
committed by
Nicolas Sarlin
parent
7d044b00a3
commit
2af4676588
@@ -106,7 +106,14 @@ impl VersionizeAttribute {
|
||||
attribute_builder.into =
|
||||
Some(parse_path_ignore_quotes(&name_value.value)?);
|
||||
}
|
||||
// parse versionize(bound = "Type: Bound")
|
||||
// parse versionize(dispatch = "Type")
|
||||
} else if name_value.path.is_ident("dispatch") {
|
||||
if attribute_builder.dispatch_enum.is_some() {
|
||||
return Err(Self::default_error(meta.span()));
|
||||
} else {
|
||||
attribute_builder.dispatch_enum =
|
||||
Some(parse_path_ignore_quotes(&name_value.value)?);
|
||||
}
|
||||
} else {
|
||||
return Err(Self::default_error(meta.span()));
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ use tfhe_versionable::{Unversionize, Upgrade, Version, Versionize, VersionsDispa
|
||||
|
||||
// The structure that should be versioned, as defined in your code
|
||||
#[derive(Versionize)]
|
||||
#[versionize(MyStructVersions)] // Link to the enum type that will holds all the versions of this
|
||||
// type
|
||||
// We have to link to the enum type that will holds all the versions of this
|
||||
// type. This can also be written `#[versionize(dispatch = MyStructVersions)]`.
|
||||
#[versionize(MyStructVersions)]
|
||||
struct MyStruct<T> {
|
||||
attr: T,
|
||||
builtin: u32,
|
||||
|
||||
@@ -37,6 +37,18 @@ pub struct MyStruct2<T, U> {
|
||||
field1: U,
|
||||
}
|
||||
|
||||
#[derive(Versionize)]
|
||||
#[versionize(dispatch = MyStruct3Versions)]
|
||||
pub struct MyStruct3<T> {
|
||||
field0: u64,
|
||||
field1: T,
|
||||
}
|
||||
|
||||
#[derive(VersionsDispatch)]
|
||||
pub enum MyStruct3Versions<T> {
|
||||
V0(MyStruct3<T>),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_impl_all!(MyEmptyStruct: Version);
|
||||
assert_impl_all!(MyEmptyStruct2: Version);
|
||||
@@ -47,7 +59,9 @@ fn main() {
|
||||
|
||||
assert_impl_all!(MyAnonStruct3<u64>: Version);
|
||||
|
||||
assert_impl_all!(MyStruct<u32>: Version);
|
||||
assert_impl_all!(MyStruct<u32>: Versionize);
|
||||
|
||||
assert_impl_all!(MyStruct2<usize, String>: Version);
|
||||
|
||||
assert_impl_all!(MyStruct3<u32>: Versionize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user