pub enum CustomVariableConfig {
FloatingPoint {
initial: OrderedFloat<f64>,
},
SignedInteger {
initial: i64,
},
UnsignedInteger {
initial: u64,
},
Boolean {
initial: bool,
},
}Expand description
codec between StateVar values and basic Rust types. all stateful information in Compass is encoded as a vector of floating point values. a codec provides a mapping to and from types in order to represent different real-numbered and discrete information types.
because Rust does not support dependent types and trait objects cannot return “Self“s, we are limited in how we generalize over unit types. these codecs substitute for the limitations in the type system, providing a validation check on encoding and decoding to/from StateVar instances and also a codec value that can be instantiated from configuration for a given StateModel.
warning: this could backfire, but probably in extreme cases that can be avoided. for example, if the user selects esoteric integer values that are not well-represented in floating point, then an encode -> decode roundtrip may not be idempotent.
Variants§
Implementations§
Source§impl CustomVariableConfig
impl CustomVariableConfig
pub const DEFAULT: Self
pub fn name(&self) -> String
pub fn initial(&self) -> Result<StateVariable, StateModelError>
pub fn encode_f64(&self, value: &f64) -> Result<StateVariable, StateModelError>
pub fn encode_i64(&self, value: &i64) -> Result<StateVariable, StateModelError>
pub fn encode_u64(&self, value: &u64) -> Result<StateVariable, StateModelError>
pub fn encode_bool( &self, value: &bool, ) -> Result<StateVariable, StateModelError>
pub fn decode_f64(&self, value: &StateVariable) -> Result<f64, StateModelError>
pub fn decode_i64(&self, value: &StateVariable) -> Result<i64, StateModelError>
pub fn decode_u64(&self, value: &StateVariable) -> Result<u64, StateModelError>
pub fn decode_bool( &self, value: &StateVariable, ) -> Result<bool, StateModelError>
Trait Implementations§
Source§impl Clone for CustomVariableConfig
impl Clone for CustomVariableConfig
Source§fn clone(&self) -> CustomVariableConfig
fn clone(&self) -> CustomVariableConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CustomVariableConfig
impl Debug for CustomVariableConfig
Source§impl Default for CustomVariableConfig
impl Default for CustomVariableConfig
Source§impl<'de> Deserialize<'de> for CustomVariableConfig
impl<'de> Deserialize<'de> for CustomVariableConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for CustomVariableConfig
impl Display for CustomVariableConfig
Source§impl PartialEq for CustomVariableConfig
impl PartialEq for CustomVariableConfig
Source§impl PartialOrd for CustomVariableConfig
impl PartialOrd for CustomVariableConfig
Source§impl Serialize for CustomVariableConfig
impl Serialize for CustomVariableConfig
impl Copy for CustomVariableConfig
impl Eq for CustomVariableConfig
impl StructuralPartialEq for CustomVariableConfig
Auto Trait Implementations§
impl Freeze for CustomVariableConfig
impl RefUnwindSafe for CustomVariableConfig
impl Send for CustomVariableConfig
impl Sync for CustomVariableConfig
impl Unpin for CustomVariableConfig
impl UnsafeUnpin for CustomVariableConfig
impl UnwindSafe for CustomVariableConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more