pub trait ValueFrom<Src>: Sized {
type Err: Error;
// Required method
fn value_from(src: Src) -> Result<Self, Self::Err>;
}
Expand description
This trait is used to perform an exact, value-preserving conversion.
Where possible, prefer implementing this trait over ValueInto
, but prefer using ValueInto
for generic constraints.
§Details
Implementations of this trait should be reflexive, associative and commutative (in the absence of conversion errors). That is, all possible cycles of ValueFrom
conversions (for which each “step” has a defined implementation) should produce the same result, with a given value either being “round-tripped” exactly, or an error being produced.
Required Associated Types§
Required Methods§
Sourcefn value_from(src: Src) -> Result<Self, Self::Err>
fn value_from(src: Src) -> Result<Self, Self::Err>
Convert the given value into an exactly equivalent representation.
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.