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>

impl IntoVar<CommandScope> for &'static str

impl IntoVar<ZIndex> for u32

impl IntoVar<WidgetId> for &'static str

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

impl IntoVar<WidgetId> for Txt

impl IntoVar<WindowId> for &'static str

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

impl IntoVar<WindowId> for Txt

impl<const N: usize> IntoVar<Shortcuts> for [Shortcut; N]

impl IntoVar<ColorMatrix> for [f32; 20]

impl IntoVar<Hsla> for Hsva

impl IntoVar<Hsla> for Rgba

impl IntoVar<Hsva> for Hsla

impl IntoVar<Hsva> for Rgba

impl IntoVar<Rgba> for Hsla

impl IntoVar<Rgba> for Hsva

impl<L: Into<Length> + Copy> IntoVar<GradientStops> for &[(Hsla, L)]

impl<L: Into<Length> + Copy> IntoVar<GradientStops> for &[(Hsva, L)]

impl<L: Into<Length> + Copy> IntoVar<GradientStops> for &[(Rgba, L)]

impl<L: Into<Length> + Copy, const N: usize> IntoVar<GradientStops> for &[(Hsla, L); N]

impl<L: Into<Length> + Copy, const N: usize> IntoVar<GradientStops> for &[(Hsva, L); N]

impl<L: Into<Length> + Copy, const N: usize> IntoVar<GradientStops> for &[(Rgba, L); N]

impl<L: Into<Length> + Copy, const N: usize> IntoVar<GradientStops> for [(Hsla, L); N]

impl<L: Into<Length> + Copy, const N: usize> IntoVar<GradientStops> for [(Hsva, L); N]

impl<L: Into<Length> + Copy, const N: usize> IntoVar<GradientStops> for [(Rgba, L); N]

impl<L: Into<Rgba>, D: Into<Rgba>> IntoVar<LightDark> for (L, D)

impl<const N: usize> IntoVar<GradientStops> for &[Hsla; N]

impl<const N: usize> IntoVar<GradientStops> for &[Hsva; N]

impl<const N: usize> IntoVar<GradientStops> for &[Rgba; N]

impl<const N: usize> IntoVar<GradientStops> for [Hsla; N]

impl<const N: usize> IntoVar<GradientStops> for [Hsva; N]

impl<const N: usize> IntoVar<GradientStops> for [Rgba; N]

impl IntoVar<CategoryId> for &'static str

impl IntoVar<FontName> for &'static str

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

impl IntoVar<FontNames> for &'static str

impl IntoVar<FontNames> for Vec<&'static str>

impl IntoVar<Txt> for FontName

impl<const N: usize> IntoVar<FontNames> for [&'static str; N]

impl<const N: usize> IntoVar<FontNames> for [String; N]

impl<const N: usize> IntoVar<FontNames> for [FontName; N]

impl<const N: usize> IntoVar<FontNames> for [Txt; N]

impl IntoVar<ImageSource> for &'static [u8]

impl IntoVar<ImageSource> for (Uri, &'static str)

impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (&'static [u8], F)

impl<F: Into<ImageDataFormat>, const N: usize> IntoVar<ImageSource> for (&'static [u8; N], F)

impl<const N: usize> IntoVar<ImageSource> for &'static [u8; N]

impl IntoVar<TabIndex> for u32

impl IntoVar<L10nArgument> for &'static str

impl IntoVar<L10nArgument> for FluentNumber

impl IntoVar<LangFilePath> for &'static str

impl IntoVar<Langs> for Lang

impl IntoVar<WindowIcon> for &'static [u8]

impl<F: Into<ImageDataFormat>> IntoVar<WindowIcon> for (&'static [u8], F)

impl<F: Into<ImageDataFormat>, const N: usize> IntoVar<WindowIcon> for (&'static [u8; N], F)

impl<const N: usize> IntoVar<WindowIcon> for &'static [u8; N]

impl IntoVar<Length> for f32

impl IntoVar<Length> for i32

impl IntoVar<Length> for Dip

impl IntoVar<Length> for Px

impl IntoVar<Align> for Factor

impl IntoVar<Line> for PxLine

impl IntoVar<Point> for Length

impl IntoVar<Point> for f32

impl IntoVar<Point> for i32

impl IntoVar<Point> for Align

impl IntoVar<Point> for Factor

impl IntoVar<Point> for Vector

impl IntoVar<Ppi> for Ppm

impl IntoVar<Ppm> for Ppi

impl IntoVar<Rect> for Size

impl IntoVar<Rect> for DipRect

impl IntoVar<Rect> for PxRect

impl IntoVar<Size> for Length

impl IntoVar<Size> for f32

impl IntoVar<Size> for i32

impl IntoVar<Size> for Factor

impl IntoVar<Size> for Rect

impl IntoVar<Size> for Vector

impl IntoVar<Size> for DipSize

impl IntoVar<Size> for PxSize

impl IntoVar<Vector> for f32

impl IntoVar<Vector> for i32

impl IntoVar<Vector> for Dip

impl IntoVar<Vector> for Point

impl IntoVar<Vector> for Px

impl IntoVar<Vector> for Size

impl<C, R> IntoVar<GridSpacing> for (C, R)
where C: Into<Length> + Clone, R: Into<Length> + Clone,

impl<O: Into<Point>, S: Into<Size>> IntoVar<Rect> for (O, S)

impl<T, R, B, L> IntoVar<SideOffsets> for (T, R, B, L)
where T: Into<Length> + Clone, R: Into<Length> + Clone, B: Into<Length> + Clone, L: Into<Length> + Clone,

impl<TB, LR> IntoVar<SideOffsets> for (TB, LR)
where TB: Into<Length> + Clone, LR: Into<Length> + Clone,

impl<W, H> IntoVar<Size> for (W, H)
where W: Into<Length> + Clone, H: Into<Length> + Clone,

impl<X, Y> IntoVar<Point> for (X, Y)
where X: Into<Length> + Clone, Y: Into<Length> + Clone,

impl<X, Y> IntoVar<Vector> for (X, Y)
where X: Into<Length> + Clone, Y: Into<Length> + Clone,

impl<X, Y, W, H> IntoVar<Rect> for (X, Y, W, H)
where X: Into<Length> + Clone, Y: Into<Length> + Clone, W: Into<Length> + Clone, H: Into<Length> + Clone,

impl<X: Into<Factor>, Y: Into<Factor>> IntoVar<Align> for (X, bool, Y)

impl<X: Into<Factor>, Y: Into<Factor>> IntoVar<Align> for (X, Y)

impl IntoVar<f32> for Progress

impl IntoVar<Progress> for &'static str

impl IntoVar<Progress> for f32

impl IntoVar<Progress> for Txt

impl IntoVar<DragDropData> for &'static str

impl IntoVar<FileDialogFilters> for &'static str

impl IntoVar<ImagePpi> for (f32, f32)

impl IntoVar<ImagePpi> for f32

impl IntoVar<ScrollToTarget> for &'static str

impl<F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static> IntoVar<SmoothScrolling> for (Duration, F)

impl<P: Into<Point>, O: Into<Point>> IntoVar<StackDirection> for (P, O, bool)

impl IntoVar<TextOverflow> for &'static str

impl IntoVar<GlyphSource> for &'static str