mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-09 22:57:59 -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 =
|
attribute_builder.into =
|
||||||
Some(parse_path_ignore_quotes(&name_value.value)?);
|
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 {
|
} else {
|
||||||
return Err(Self::default_error(meta.span()));
|
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
|
// The structure that should be versioned, as defined in your code
|
||||||
#[derive(Versionize)]
|
#[derive(Versionize)]
|
||||||
#[versionize(MyStructVersions)] // Link to the enum type that will holds all the versions of this
|
// We have to link to the enum type that will holds all the versions of this
|
||||||
// type
|
// type. This can also be written `#[versionize(dispatch = MyStructVersions)]`.
|
||||||
|
#[versionize(MyStructVersions)]
|
||||||
struct MyStruct<T> {
|
struct MyStruct<T> {
|
||||||
attr: T,
|
attr: T,
|
||||||
builtin: u32,
|
builtin: u32,
|
||||||
|
|||||||
@@ -37,6 +37,18 @@ pub struct MyStruct2<T, U> {
|
|||||||
field1: 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() {
|
fn main() {
|
||||||
assert_impl_all!(MyEmptyStruct: Version);
|
assert_impl_all!(MyEmptyStruct: Version);
|
||||||
assert_impl_all!(MyEmptyStruct2: Version);
|
assert_impl_all!(MyEmptyStruct2: Version);
|
||||||
@@ -47,7 +59,9 @@ fn main() {
|
|||||||
|
|
||||||
assert_impl_all!(MyAnonStruct3<u64>: Version);
|
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!(MyStruct2<usize, String>: Version);
|
||||||
|
|
||||||
|
assert_impl_all!(MyStruct3<u32>: Versionize);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user