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§
Sourcefn into_optioned(self) -> Self::Optioned
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.
Sourcefn try_from_optioned(value: Self::Optioned) -> Result<Self, Error>
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.
Sourcefn merge(&mut self, other: Self::Optioned) -> Result<(), Error>
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 typeOption<T>and valueNoneforselfand typeOption<T::Optioned>andSomevalue forother. TheT::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.
impl OptionableConvert for Value
Available on crate feature
serde_json only.Source§impl OptionableConvert for bool
impl OptionableConvert for bool
Source§impl OptionableConvert for char
impl OptionableConvert for char
Source§impl OptionableConvert for f32
impl OptionableConvert for f32
Source§impl OptionableConvert for f64
impl OptionableConvert for f64
Source§impl OptionableConvert for i8
impl OptionableConvert for i8
Source§impl OptionableConvert for i16
impl OptionableConvert for i16
Source§impl OptionableConvert for i32
impl OptionableConvert for i32
Source§impl OptionableConvert for i64
impl OptionableConvert for i64
Source§impl OptionableConvert for i128
impl OptionableConvert for i128
Source§impl OptionableConvert for isize
impl OptionableConvert for isize
Source§impl OptionableConvert for u8
impl OptionableConvert for u8
Source§impl OptionableConvert for u16
impl OptionableConvert for u16
Source§impl OptionableConvert for u32
impl OptionableConvert for u32
Source§impl OptionableConvert for u64
impl OptionableConvert for u64
Source§impl OptionableConvert for u128
impl OptionableConvert for u128
Source§impl OptionableConvert for ()
impl OptionableConvert for ()
Source§impl OptionableConvert for usize
impl OptionableConvert for usize
Source§impl OptionableConvert for String
Available on crate features alloc or std only.
impl OptionableConvert for String
Available on crate features
alloc or std only.Source§impl OptionableConvert for Duration
Available on crate feature std only.
impl OptionableConvert for Duration
Available on crate feature
std only.Source§impl OptionableConvert for OsString
Available on crate feature std only.
impl OptionableConvert for OsString
Available on crate feature
std only.Source§impl OptionableConvert for PathBuf
Available on crate feature std only.
impl OptionableConvert for PathBuf
Available on crate feature
std only.Source§impl<K: Ord + Hash, T: OptionableConvert, S: BuildHasher + Default> OptionableConvert for HashMap<K, T, S>
Available on crate feature std only.
impl<K: Ord + Hash, T: OptionableConvert, S: BuildHasher + Default> OptionableConvert for HashMap<K, T, S>
Available on crate feature
std only.Source§impl<K: Ord, T: OptionableConvert> OptionableConvert for BTreeMap<K, T>
Available on crate features alloc or std only.
impl<K: Ord, T: OptionableConvert> OptionableConvert for BTreeMap<K, T>
Available on crate features
alloc or std only.Source§impl<T> OptionableConvert for BinaryHeap<T>
Available on crate features alloc or std only.
impl<T> OptionableConvert for BinaryHeap<T>
Available on crate features
alloc or std only.fn into_optioned(self) -> <BinaryHeap<T> as Optionable>::Optioned
fn try_from_optioned( value: <BinaryHeap<T> as Optionable>::Optioned, ) -> Result<Self, Error>
fn merge( &mut self, other: <BinaryHeap<T> as Optionable>::Optioned, ) -> Result<(), Error>
Source§impl<T> OptionableConvert for BTreeSet<T>
Available on crate features alloc or std only.
impl<T> OptionableConvert for BTreeSet<T>
Available on crate features
alloc or std only.fn into_optioned(self) -> <BTreeSet<T> as Optionable>::Optioned
fn try_from_optioned( value: <BTreeSet<T> as Optionable>::Optioned, ) -> Result<Self, Error>
fn merge( &mut self, other: <BTreeSet<T> as Optionable>::Optioned, ) -> Result<(), Error>
Source§impl<T, S: Default + BuildHasher> OptionableConvert for HashSet<T, S>
Available on crate feature std only.
impl<T, S: Default + BuildHasher> OptionableConvert for HashSet<T, S>
Available on crate feature
std only.fn into_optioned(self) -> <HashSet<T, S> as Optionable>::Optioned
fn try_from_optioned( value: <HashSet<T, S> as Optionable>::Optioned, ) -> Result<Self, Error>
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.
impl<T, const N: usize> OptionableConvert for [T; N]
Available on crate features
alloc or std only.Source§impl<T: OptionableConvert + Clone> OptionableConvert for Cow<'_, T>
Available on crate features alloc or std only.
impl<T: OptionableConvert + Clone> OptionableConvert for Cow<'_, T>
Available on crate features
alloc or std only.Source§impl<T: OptionableConvert> OptionableConvert for Option<T>
impl<T: OptionableConvert> OptionableConvert for Option<T>
Source§impl<T: OptionableConvert> OptionableConvert for Box<T>
Available on crate features alloc or std only.
impl<T: OptionableConvert> OptionableConvert for Box<T>
Available on crate features
alloc or std only.Source§impl<T: OptionableConvert> OptionableConvert for LinkedList<T>
Available on crate features alloc or std only.
impl<T: OptionableConvert> OptionableConvert for LinkedList<T>
Available on crate features
alloc or std only.fn into_optioned(self) -> <LinkedList<T> as Optionable>::Optioned
fn try_from_optioned( value: <LinkedList<T> as Optionable>::Optioned, ) -> Result<Self, Error>
fn merge( &mut self, other: <LinkedList<T> as Optionable>::Optioned, ) -> Result<(), Error>
Source§impl<T: OptionableConvert> OptionableConvert for VecDeque<T>
Available on crate features alloc or std only.
impl<T: OptionableConvert> OptionableConvert for VecDeque<T>
Available on crate features
alloc or std only.fn into_optioned(self) -> <VecDeque<T> as Optionable>::Optioned
fn try_from_optioned( value: <VecDeque<T> as Optionable>::Optioned, ) -> Result<Self, Error>
fn merge( &mut self, other: <VecDeque<T> as Optionable>::Optioned, ) -> Result<(), Error>
Source§impl<T: OptionableConvert> OptionableConvert for Vec<T>
Available on crate features alloc or std only.
impl<T: OptionableConvert> OptionableConvert for Vec<T>
Available on crate features
alloc or std only.