Struct canadensis::register::basic::ValidatedRegister
source · [−]Expand description
A register with a validation function that can reject invalid write operations
Each write operation is checked with the validator. If the validator returns false, the value of the register does not change.
Examples
fn is_finite_float(value: &f32) -> bool {
!(value.is_infinite() || value.is_nan())
}
let mut finite_float_register =
ValidatedRegister::new("test.float", true, true, is_finite_float);
assert!(finite_float_register
.write(&Value::Real32(Real32 { value: heapless::Vec::from_slice(&[37.0]).unwrap() }))
.is_ok());
assert!(finite_float_register
.write(&Value::Real32(Real32 {
value: heapless::Vec::from_slice(&[f32::INFINITY]).unwrap()}
))
.is_err());
assert!(finite_float_register
.write(&Value::Real32(Real32 {
value:heapless::Vec::from_slice(&[f32::NEG_INFINITY]).unwrap()}
))
.is_err());
assert!(finite_float_register
.write(&Value::Real32(Real32 {
value: heapless::Vec::from_slice(&[f32::NAN]).unwrap()}
))
.is_err());
Implementations
sourceimpl<T, V> ValidatedRegister<T, V> where
T: Default,
impl<T, V> ValidatedRegister<T, V> where
T: Default,
sourceimpl<T, V> ValidatedRegister<T, V>
impl<T, V> ValidatedRegister<T, V>
sourcepub fn with_value(
name: &'static str,
mutable: bool,
persistent: bool,
value: T,
validator: V
) -> Self
pub fn with_value(
name: &'static str,
mutable: bool,
persistent: bool,
value: T,
validator: V
) -> Self
Creates a register with the provided initial value
The validator should consider the provided value to be valid
Trait Implementations
sourceimpl<T, V> Debug for ValidatedRegister<T, V> where
T: Debug,
impl<T, V> Debug for ValidatedRegister<T, V> where
T: Debug,
sourceimpl<T, V> Register for ValidatedRegister<T, V> where
T: RegisterType + Clone,
V: Validator<T>,
impl<T, V> Register for ValidatedRegister<T, V> where
T: RegisterType + Clone,
V: Validator<T>,
Auto Trait Implementations
impl<T, V> RefUnwindSafe for ValidatedRegister<T, V> where
T: RefUnwindSafe,
V: RefUnwindSafe,
impl<T, V> Send for ValidatedRegister<T, V> where
T: Send,
V: Send,
impl<T, V> Sync for ValidatedRegister<T, V> where
T: Sync,
V: Sync,
impl<T, V> Unpin for ValidatedRegister<T, V> where
T: Unpin,
V: Unpin,
impl<T, V> UnwindSafe for ValidatedRegister<T, V> where
T: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more