FromOptionalField

Trait FromOptionalField 

Source
pub trait FromOptionalField<T> {
    // Required methods
    fn optional(self) -> Result<Option<T>, Error>;
    fn required(self, field: impl Into<String>) -> Result<T, Error>;
}
Expand description

An extension trait that adds the methods optional and required to any Option containing a type implementing TryInto<U, Error = Error>

Required Methods§

Source

fn optional(self) -> Result<Option<T>, Error>

Converts an optional protobuf field to an option of a different type

Returns None if the option is None, otherwise calls TryInto::try_into on the contained data, returning any error encountered

Source

fn required(self, field: impl Into<String>) -> Result<T, Error>

Converts an optional protobuf field to a different type, returning an error if None

Returns Error::MissingRequiredField if None, otherwise calls TryInto::try_into on the contained data, returning any error encountered

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.

Implementations on Foreign Types§

Source§

impl<T, U> FromOptionalField<U> for Option<T>
where T: TryInto<U, Error = Error>,

Source§

fn optional(self) -> Result<Option<U>, Error>

Source§

fn required(self, field: impl Into<String>) -> Result<U, Error>

Implementors§