pub struct ValidatedRegister<T, V = fn(_: &T) -> bool> { /* private fields */ }
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

Creates a register containing the default value of type T

The validator should consider T::default() to be valid.

Creates a register with the provided initial value

The validator should consider the provided value to be valid

Returns a reference to the value of this register

Returns a mutable reference to the value of this register

Sets the value of this register

Trait Implementations

Formats the value using the given formatter. Read more

Returns the name of this register Read more

Returns information about how this register can be accessed

Reads this register and returns its value Read more

Writes the value of this register Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.