OptionableConvert

Trait OptionableConvert 

Source
pub trait OptionableConvert: Sized + Optionable {
    // Required methods
    fn into_optioned(self) -> Self::Optioned;
    fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>;
    fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>;
}
Expand description

Extension trait for sized Optionable to transform in and from optioned objects as well as merging.

Required Methods§

Source

fn into_optioned(self) -> Self::Optioned

Transforms this object into an optioned variant which all fields set.

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

Source

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Try to build this full type from its optioned variant.

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

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

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Merge the optioned values into this 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.

Implementations on Foreign Types§

Source§

impl OptionableConvert for Value

Available on crate feature serde_json only.
Source§

fn into_optioned(self) -> Value

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for bool

Source§

fn into_optioned(self) -> bool

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for char

Source§

fn into_optioned(self) -> char

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for f32

Source§

fn into_optioned(self) -> f32

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for f64

Source§

fn into_optioned(self) -> f64

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for i8

Source§

fn into_optioned(self) -> i8

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for i16

Source§

fn into_optioned(self) -> i16

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for i32

Source§

fn into_optioned(self) -> i32

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for i64

Source§

fn into_optioned(self) -> i64

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for i128

Source§

fn into_optioned(self) -> i128

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for isize

Source§

fn into_optioned(self) -> isize

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for u8

Source§

fn into_optioned(self) -> u8

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for u16

Source§

fn into_optioned(self) -> u16

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for u32

Source§

fn into_optioned(self) -> u32

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for u64

Source§

fn into_optioned(self) -> u64

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for u128

Source§

fn into_optioned(self) -> u128

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for ()

Source§

fn into_optioned(self)

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for usize

Source§

fn into_optioned(self) -> usize

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for String

Available on crate features alloc or std only.
Source§

fn into_optioned(self) -> String

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for Duration

Available on crate feature std only.
Source§

fn into_optioned(self) -> Duration

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for OsString

Available on crate feature std only.
Source§

fn into_optioned(self) -> OsString

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl OptionableConvert for PathBuf

Available on crate feature std only.
Source§

fn into_optioned(self) -> PathBuf

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl<K: Ord + Hash, T: OptionableConvert, S: BuildHasher + Default> OptionableConvert for HashMap<K, T, S>
where T::Optioned: Sized,

Available on crate feature std only.
Source§

fn into_optioned(self) -> HashMap<K, T::Optioned, S>

Source§

fn try_from_optioned(value: HashMap<K, T::Optioned, S>) -> Result<Self, Error>

Source§

fn merge(&mut self, other: HashMap<K, T::Optioned, S>) -> Result<(), Error>

Source§

impl<K: Ord, T: OptionableConvert> OptionableConvert for BTreeMap<K, T>
where T::Optioned: Sized,

Available on crate features alloc or std only.
Source§

fn into_optioned(self) -> BTreeMap<K, T::Optioned>

Source§

fn try_from_optioned(value: BTreeMap<K, T::Optioned>) -> Result<Self, Error>

Source§

fn merge(&mut self, other: BTreeMap<K, T::Optioned>) -> Result<(), Error>

Source§

impl<T> OptionableConvert for BinaryHeap<T>

Available on crate features alloc or std only.
Source§

impl<T> OptionableConvert for BTreeSet<T>

Available on crate features alloc or std only.
Source§

impl<T, S: Default + BuildHasher> OptionableConvert for HashSet<T, S>
where T: Ord + Hash + OptionableConvert, T::Optioned: Sized + Eq + Hash,

Available on crate feature std only.
Source§

fn into_optioned(self) -> <HashSet<T, S> as Optionable>::Optioned

Source§

fn try_from_optioned( value: <HashSet<T, S> as Optionable>::Optioned, ) -> Result<Self, Error>

Source§

fn merge( &mut self, other: <HashSet<T, S> as Optionable>::Optioned, ) -> Result<(), Error>

Source§

impl<T, const N: usize> OptionableConvert for [T; N]

Available on crate features alloc or std only.
Source§

fn into_optioned(self) -> Self::Optioned

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl<T: OptionableConvert + Clone> OptionableConvert for Cow<'_, T>
where T::Optioned: Clone,

Available on crate features alloc or std only.
Source§

fn into_optioned(self) -> Self::Optioned

Source§

fn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Self::Optioned) -> Result<(), Error>

Source§

impl<T: OptionableConvert> OptionableConvert for Option<T>
where T::Optioned: Sized,

Source§

impl<T: OptionableConvert> OptionableConvert for Box<T>
where T::Optioned: Sized,

Available on crate features alloc or std only.
Source§

fn into_optioned(self) -> Box<T::Optioned>

Source§

fn try_from_optioned(value: Box<T::Optioned>) -> Result<Self, Error>

Source§

fn merge(&mut self, other: Box<T::Optioned>) -> Result<(), Error>

Source§

impl<T: OptionableConvert> OptionableConvert for LinkedList<T>
where T::Optioned: Sized,

Available on crate features alloc or std only.
Source§

impl<T: OptionableConvert> OptionableConvert for VecDeque<T>
where T::Optioned: Sized,

Available on crate features alloc or std only.
Source§

impl<T: OptionableConvert> OptionableConvert for Vec<T>
where T::Optioned: Sized,

Available on crate features alloc or std only.
Source§

fn into_optioned(self) -> <Vec<T> as Optionable>::Optioned

Source§

fn try_from_optioned( value: <Vec<T> as Optionable>::Optioned, ) -> Result<Self, Error>

Source§

fn merge( &mut self, other: <Vec<T> as Optionable>::Optioned, ) -> Result<(), Error>

Implementors§