pub trait TryFromOption: Sized {
// Required method
fn try_from(value: &impl MessageOption) -> Option<Self>;
}
Expand description
A trait semantically similar to TryFrom, but rather than being generic over the source, this trait is specialized in being from any impl of MessageOption.
Types that implement this implicitly encode an extra piece of information, their option number:
Options passed in that don’t have a matching number need to be ignored with a None
return
value.
In passing, we also introduce a lifetime for the option (we work from(&O)
instead of
from(O)
) because this is always used with data copied out (as the MessageOption doesn’t allow
long-term references into it anyway).
This uses an Option and not a Result, because the main way in which it is used is through
take_into
, which leaves unprocessable options in the stream for later failing when critical
options are rejected. This pattern of usage also means that non-critical options that should
cause errors need to implement TryFromOption for Result<Good, Bad>
, and raise an error of
their own when Some(Bad(_))
is found.
Required Methods§
fn try_from(value: &impl MessageOption) -> Option<Self>
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.