zng_var

Trait IntoVar

source
pub trait IntoVar<T: VarValue> {
    type Var: Var<T>;

    // Required method
    fn into_var(self) -> Self::Var;

    // Provided method
    fn into_boxed_var(self) -> BoxedVar<T>
       where Self: Sized { ... }
}
Expand description

A value-to-var conversion that consumes the value.

Every Var<T> implements this to convert to itself, every VarValue implements this to convert to a LocalVar<T>.

This trait is used by most properties, it allows then to accept literal values, variables and context variables all with a single signature. Together with Var<T> this gives properties great flexibility of usage, at zero-cost. Widget when blocks also use IntoVar<T> to support changing the property value depending on the widget state.

Value types can also manually implement this to support a shorthand literal syntax for when they are used in properties, this converts the shorthand value like a tuple into the actual value type and wraps it into a variable, usually LocalVar too. They can implement the trait multiple times to support different shorthand syntaxes or different types in the shorthand value.

Required Associated Types§

source

type Var: Var<T>

Variable type that will wrap the T value.

This is the LocalVar for most types or Self for variable types.

Required Methods§

source

fn into_var(self) -> Self::Var

Converts the source value into a var.

Provided Methods§

source

fn into_boxed_var(self) -> BoxedVar<T>
where Self: Sized,

Converts into BoxedVar<T>.

This method exists to help the type system infer the type in this scenario:

fn foo(foo: impl IntoVar<bool>) { }

foo(if bar {
    BAR_VAR.map(|b| !*b).boxed()
} else {
    true.into_boxed_var()
});

We need a BoxedVar<bool> to unify the input types that can be a map var or a LocalVar<bool>. Writing true.into_var().boxed() causes the type inference to fail, requiring us to write IntoVar::<bool>::into_var(true).boxed().

Implementations on Foreign Types§

source§

impl IntoVar<Cow<'static, str>> for Txt

source§

type Var = LocalVar<Cow<'static, str>>

source§

fn into_var(self) -> Self::Var

source§

impl IntoVar<Option<Orientation2D>> for Orientation2D

source§

impl IntoVar<Option<bool>> for bool

source§

impl IntoVar<Option<char>> for char

source§

impl IntoVar<Option<f32>> for f32

source§

impl IntoVar<Option<f64>> for f64

source§

impl IntoVar<Option<i8>> for i8

source§

type Var = LocalVar<Option<i8>>

source§

fn into_var(self) -> Self::Var

source§

impl IntoVar<Option<i16>> for i16

source§

impl IntoVar<Option<i32>> for i32

source§

impl IntoVar<Option<i64>> for i64

source§

impl IntoVar<Option<i128>> for i128

source§

impl IntoVar<Option<isize>> for isize

source§

impl IntoVar<Option<u8>> for u8

source§

type Var = LocalVar<Option<u8>>

source§

fn into_var(self) -> Self::Var

source§

impl IntoVar<Option<u16>> for u16

source§

impl IntoVar<Option<u32>> for u32

source§

impl IntoVar<Option<u64>> for u64

source§

impl IntoVar<Option<u128>> for u128

source§

impl IntoVar<Option<usize>> for usize

source§

impl IntoVar<Deadline> for DInstant

source§

impl IntoVar<Deadline> for Duration

source§

impl IntoVar<Txt> for &'static str

source§

type Var = LocalVar<Txt>

source§

fn into_var(self) -> Self::Var

source§

impl IntoVar<Txt> for Cow<'static, str>

source§

type Var = LocalVar<Txt>

source§

fn into_var(self) -> Self::Var

source§

impl IntoVar<Txt> for char

source§

type Var = LocalVar<Txt>

source§

fn into_var(self) -> Self::Var

source§

impl IntoVar<Txt> for String

source§

type Var = LocalVar<Txt>

source§

fn into_var(self) -> Self::Var

source§

impl IntoVar<AngleDegree> for AngleGradian

source§

impl IntoVar<AngleDegree> for AngleRadian

source§

impl IntoVar<AngleDegree> for AngleTurn

source§

impl IntoVar<AngleGradian> for AngleDegree

source§

impl IntoVar<AngleGradian> for AngleRadian

source§

impl IntoVar<AngleGradian> for AngleTurn

source§

impl IntoVar<AngleRadian> for AngleDegree

source§

impl IntoVar<AngleRadian> for AngleGradian

source§

impl IntoVar<AngleRadian> for AngleTurn

source§

impl IntoVar<AngleTurn> for AngleDegree

source§

impl IntoVar<AngleTurn> for AngleGradian

source§

impl IntoVar<AngleTurn> for AngleRadian

source§

impl IntoVar<ByteLength> for usize

source§

impl IntoVar<Factor> for bool

source§

impl IntoVar<Factor> for f32

source§

impl IntoVar<Factor> for FactorPercent

source§

impl IntoVar<FactorPercent> for Factor

source§

impl IntoVar<EasingTime> for Factor

source§

impl IntoVar<String> for Txt

source§

impl IntoVar<PathBuf> for Txt

Implementors§

source§

impl<I: VarValue, O: VarValue, S: Var<I>> IntoVar<O> for MapRef<I, O, S>

source§

type Var = MapRef<I, O, S>

source§

impl<I: VarValue, O: VarValue, S: Var<I>> IntoVar<O> for MapRefBidi<I, O, S>

source§

type Var = MapRefBidi<I, O, S>

source§

impl<T, V> IntoVar<T> for ArcFlatMapVar<T, V>
where T: VarValue, V: Var<T>,

source§

impl<T: VarValue> IntoVar<T> for ArcVar<T>

source§

impl<T: VarValue> IntoVar<T> for ContextVar<T>

source§

impl<T: VarValue> IntoVar<T> for LocalVar<T>

source§

impl<T: VarValue> IntoVar<T> for ArcMergeVar<T>

source§

impl<T: VarValue> IntoVar<T> for ArcWhenVar<T>

source§

impl<T: VarValue> IntoVar<T> for ContextualizedVar<T>

source§

impl<T: VarValue> IntoVar<T> for BoxedVar<T>

source§

type Var = Box<dyn VarBoxed<T>>

source§

impl<T: VarValue> IntoVar<T> for T

source§

impl<T: VarValue, S: Var<T>> IntoVar<T> for ArcCowVar<T, S>

source§

type Var = ArcCowVar<T, S>

source§

impl<T: VarValue, V: Var<T>> IntoVar<T> for ReadOnlyVar<T, V>