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

Object Safety§

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§