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§
fn value_type(&self) -> Type
fn value_type(&self) -> Type
Returns the type identifer of self
.
This is the type of the value to be returned by to_value
.
Implementations on Foreign Types§
§impl<T> ToValue for &Twhere
T: ToValue + StaticType,
impl<T> ToValue for &Twhere T: ToValue + StaticType,
Blanket implementation for all references.
Implementors§
impl ToValue for &GStr
impl ToValue for Antialias
impl ToValue for Content
impl ToValue for druid::piet::cairo::DeviceType
impl ToValue for Extend
impl ToValue for FillRule
impl ToValue for Filter
impl ToValue for FontSlant
impl ToValue for FontType
impl ToValue for FontWeight
impl ToValue for Format
impl ToValue for HintMetrics
impl ToValue for HintStyle
impl ToValue for LineCap
impl ToValue for LineJoin
impl ToValue for Operator
impl ToValue for PathDataType
impl ToValue for PatternType
impl ToValue for RegionOverlap
impl ToValue for SubpixelOrder
impl ToValue for SurfaceType
impl ToValue for TextClusterFlags
impl ToValue for Context
impl ToValue for Device
impl ToValue for ImageSurface
impl ToValue for Matrix
impl ToValue for RecordingSurface
impl ToValue for Rectangle
impl ToValue for RectangleInt
impl ToValue for Region
impl ToValue for Surface
impl ToValue for XCBSurface
impl ToValue for NonNull<c_void>
impl ToValue for Inhibit
impl ToValue for BindingFlags
impl ToValue for BoxedValue
impl ToValue for GStr
impl ToValue for GString
impl ToValue for ILong
impl ToValue for IOCondition
impl ToValue for SendValue
impl ToValue for ULong
impl ToValue for Value
impl<'a> ToValue for &'a SendValue
impl<'a> ToValue for &'a Value
impl<T> ToValue for Option<T>where T: ToValueOptional + StaticType,
Blanket implementation for all optional types.