tfhe_versionable/
derived_traits.rs

1//! These traits are not meant to be manually implemented, they are just used in the derive macro
2//! for easier access to generated types
3
4use serde::de::DeserializeOwned;
5use serde::Serialize;
6
7use crate::UnversionizeError;
8
9/// This trait is used to mark a specific version of a given type
10pub trait Version: Sized {
11    type Ref<'vers>: From<&'vers Self> + Serialize
12    where
13        Self: 'vers;
14    type Owned: From<Self> + TryInto<Self, Error = UnversionizeError> + DeserializeOwned + Serialize;
15}
16
17/// This trait is implemented on the dispatch enum for a given type. The dispatch enum
18/// is an enum that holds all the versions of the type. Each variant should implement the
19/// `Version` trait.
20pub trait VersionsDispatch<Unversioned>: Sized {
21    type Ref<'vers>: From<&'vers Unversioned> + Serialize
22    where
23        Unversioned: 'vers;
24    type Owned: From<Unversioned>
25        + TryInto<Unversioned, Error = UnversionizeError>
26        + DeserializeOwned
27        + Serialize;
28}