pub trait ToValue {
// Required methods
fn to_value(&self) -> Value;
fn value_type(&self) -> Type;
}
Expand description
Trait to convert a value to a Value
.
Similar to other common conversion traits, the following invariants are guaranteed:
- Invertibility:
x.to_value().get().unwrap() == x
. In words,FromValue
is the inverse ofToValue
. - Idempotence:
x.to_value() == x.to_value().to_value()
. In words, applyingToValue
multiple times yields the same result as applying it once. Idempotence also applies the other way around:value.get::<Value>()
is a no-op.
There is also the possibility to wrap values within values, see BoxedValue
. All (un-)boxing needs to be done
manually, and will be preserved under the conversion methods.
The conversion methods may cause values to be cloned, which may result in reference counter changes or heap allocations depending on the source and target type.
Required Methods§
Sourcefn value_type(&self) -> Type
fn value_type(&self) -> Type
Returns the type identifier of self
.
This is the type of the value to be returned by to_value
.
Implementations on Foreign Types§
Source§impl ToValue for NonZeroI32
impl ToValue for NonZeroI32
Source§impl ToValue for NonZeroI64
impl ToValue for NonZeroI64
Source§impl ToValue for NonZeroU32
impl ToValue for NonZeroU32
Source§impl ToValue for NonZeroU64
impl ToValue for NonZeroU64
Source§impl<T: ToValueOptional + StaticType> ToValue for Option<T>
impl<T: ToValueOptional + StaticType> ToValue for Option<T>
Blanket implementation for all optional types.