mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-09 14:47:56 -05:00
feat(versionable): Handle ?Sized bounds in the proc macro
This commit is contained in:
committed by
Nicolas Sarlin
parent
51da8fe735
commit
9cc0b9050e
66
utils/tfhe-versionable/tests/unsized.rs
Normal file
66
utils/tfhe-versionable/tests/unsized.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use std::convert::Infallible;
|
||||
|
||||
use tfhe_versionable::{Unversionize, Upgrade, Version, Versionize, VersionsDispatch};
|
||||
|
||||
#[derive(Versionize)]
|
||||
#[versionize(MyStructVersions)]
|
||||
struct MyStruct<T: ?Sized> {
|
||||
builtin: u32,
|
||||
attr: T,
|
||||
}
|
||||
|
||||
#[derive(Version)]
|
||||
struct MyStructV0 {
|
||||
builtin: u32,
|
||||
}
|
||||
|
||||
impl<T: Default> Upgrade<MyStruct<T>> for MyStructV0 {
|
||||
type Error = Infallible;
|
||||
|
||||
fn upgrade(self) -> Result<MyStruct<T>, Self::Error> {
|
||||
Ok(MyStruct {
|
||||
attr: T::default(),
|
||||
builtin: self.builtin,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(VersionsDispatch)]
|
||||
#[allow(unused)]
|
||||
enum MyStructVersions<T> {
|
||||
V0(MyStructV0),
|
||||
V1(MyStruct<T>),
|
||||
}
|
||||
|
||||
mod v0 {
|
||||
use tfhe_versionable::{Versionize, VersionsDispatch};
|
||||
|
||||
#[derive(Versionize)]
|
||||
#[versionize(MyStructVersions)]
|
||||
pub(super) struct MyStruct {
|
||||
pub(super) builtin: u32,
|
||||
}
|
||||
|
||||
#[derive(VersionsDispatch)]
|
||||
#[allow(unused)]
|
||||
pub(super) enum MyStructVersions {
|
||||
V0(MyStruct),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let value = 1234;
|
||||
let ms = v0::MyStruct { builtin: value };
|
||||
|
||||
let serialized = bincode::serialize(&ms.versionize()).unwrap();
|
||||
|
||||
let unserialized =
|
||||
MyStruct::<u64>::unversionize(bincode::deserialize(&serialized).unwrap()).unwrap();
|
||||
|
||||
assert_eq!(unserialized.builtin, value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
main()
|
||||
}
|
||||
Reference in New Issue
Block a user