//! Type-state for operations with fixed or variable size. use commonware_codec::{Codec, CodecFixed}; use std::marker::PhantomData; mod sealed { use commonware_codec::Codec; /// A wrapper around a value to indicate whether it is fixed or variable size. /// Having separate wrappers for fixed and variable size values allows us to use the same /// operation type for both fixed and variable size values, while still being able to /// parameterize the operation encoding by the value type. pub trait ValueEncoding: Clone { /// The wrapped value type. type Value: Codec + Clone; } } pub(crate) use sealed::ValueEncoding; /// A fixed-size, clonable value. #[derive(Clone, Debug, PartialEq, Eq)] pub struct FixedEncoding(PhantomData); impl sealed::ValueEncoding for FixedEncoding { type Value = V; } /// A variable-size, clonable value. #[derive(Clone, Debug, PartialEq, Eq)] pub struct VariableEncoding(PhantomData); impl sealed::ValueEncoding for VariableEncoding { type Value = V; } /// A fixed-size, clonable value. pub trait FixedValue: CodecFixed + Clone {} impl + Clone> FixedValue for T {} /// A variable-size, clonable value. pub trait VariableValue: Codec + Clone {} impl VariableValue for T {}