FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    BindingTypeConverter

    trait · ferroui-reactiveui · v0.5.0

    trait BindingTypeConverter: 'static
    

    The base of the typed converters (BindingTypeConverter<TFrom, TTo>): a converter implements its typed conversion and its affinity, and the blanket implementations write IBindingTypeConverter (the source and target types, the type-erased conversion) and IBindingTypeConverterOf<From, To> from them.

    use ferroui_reactiveui::{BindingTypeConverter, IBindingTypeConverter, IBindingTypeConverterOf};
    use std::any::Any;
    
    struct Doubler;
    
    impl BindingTypeConverter for Doubler {
        type From = i32;
        type To = i64;
    
        fn affinity(&self) -> i32 {
            1
        }
    
        fn convert(&self, from: Option<&i32>, _conversion_hint: Option<&dyn Any>) -> Option<i64> {
            Some(i64::from(*from?) * 2)
        }
    }
    
    assert_eq!(Doubler.try_convert(Some(&21), None), Some(42));
    let converted = Doubler.try_convert_typed(Some(&21), None).unwrap();
    assert_eq!(converted.downcast_ref::<i64>(), Some(&42));
    assert!(Doubler.try_convert_typed(Some(&"21"), None).is_none());
    

    View source

    Members

    From

    type From: 'static
    

    The type converted from (TFrom).

    Source

    To

    type To: 'static
    

    The type converted to (TTo).

    Source

    affinity

    fn affinity(self: &Self) -> i32
    

    The affinity of the converter (GetAffinityForObjects).

    Source

    convert

    fn convert(self: &Self, from: Option<&<Self as >::From>, conversion_hint: Option<&dyn Any>) -> Option<<Self as >::To>
    

    Converts from (None for upstream's null), with an optional conversion_hint; None when the conversion fails (TryConvert).

    Source

    Trait implementations

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.