OptionedConvert

Trait OptionedConvert 

Source
pub trait OptionedConvert<T>: Sized {
    // Required methods
    fn from_optionable(value: T) -> Self;
    fn try_into_optionable(self) -> Result<T, Error>;
    fn merge_into(self, other: &mut T) -> Result<(), Error>;
}
Expand description

Trait to transform from the perspective of the optioned type back to an origin Optionable type. OptionedConvert is more general than OptionableConvert as it allows targeting a T which itself does not implement Optionable. This allows to circumvent to some degree orphan rule restrictions when deriving Optionable ( see the optioned_type helper attribute for the Optionable derive macro).

Required Methods§

Source

fn from_optionable(value: T) -> Self

Gets an optioned variant with all fields set.

We cannot implement From from the stdlib as we need to implement this for various stdlib primitives and containers.

Source

fn try_into_optionable(self) -> Result<T, Error>

Try to build a full type from this optioned variant.

§Errors
  • If fields required by the full type are not set.
Source

fn merge_into(self, other: &mut T) -> Result<(), Error>

Merge this optioned values into the provided full type. List-like types are overwritten if set in other. Maps are merged per key.

§Errors
  • There are scenarios where the full type allows some missing fields but the optioned type also does not hold enough subfields to constructs a full entry with the respective try_from. An example would be a field with type Option<T> and value None for self and type Option<T::Optioned> and Some value for other. The T::try_from(T::Optioned) can fail is fields are missing for this subfield.

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.

Implementors§