pub trait MessageOption {
// Required methods
fn number(&self) -> u16;
fn value(&self) -> &[u8];
// Provided methods
fn value_str(&self) -> Option<&str> { ... }
fn value_uint<U>(&self) -> Option<U>
where U: Unsigned + FromBytes,
U::Bytes: Sized + Default { ... }
}
Expand description
Iteration item for option values
This is the trait of items produced by ReadableMessage::options()
.
An implementation needs to allow the user to get the value as a memory slice. This is trivial
for messages that are stored in serialized form; there this can be a fat pointer.
Implementations that store options semantically (eg. as a struct Block { n: usize, m: bool, szx: u8 }
) will typically make their MessageOption large enough to contain serialized options,
or heap-allocate for them.
Required Methods§
Sourcefn number(&self) -> u16
fn number(&self) -> u16
Numeric option number
See OptionNumber on how to interpret them.
Sourcefn value(&self) -> &[u8]
fn value(&self) -> &[u8]
Obtain the option’s raw value
This can be used directly for options with opaque value semantics; for other semantics, see the value_str and value_uint helper methods.
Provided Methods§
Sourcefn value_str(&self) -> Option<&str>
fn value_str(&self) -> Option<&str>
Obtain the option’s value as a text string, or None if the option contains invalid UTF-8.
Implementations can override this to reduce the string checking overhead if they already have the value as a string internally.
Sourcefn value_uint<U>(&self) -> Option<U>
fn value_uint<U>(&self) -> Option<U>
Obtain the option’s value as a number following the uint
value
format, or None if the option is too
long for the requested number size.
Implementations can override this to reduce conversion overhead if they already have a numeric value internally as soon as U’s type is replaced with an equally capable public num trait.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.