Skip to main content

BindingValue

Struct BindingValue 

Source
pub struct BindingValue<T> { /* private fields */ }
Expand description

A value passed into a binding: a value, an “unset”/“do nothing” marker, or an error with an optional fallback value.

Implementations§

Source§

impl<T> BindingValue<T>

Source

pub fn new(value: T) -> Self

Creates a binding value holding a simple value.

Source

pub fn unset() -> Self

A binding value representing the unset state.

Source

pub fn do_nothing() -> Self

A binding value that is ignored by its target.

Source

pub fn binding_error(error: BindingError) -> Self

A binding error without a fallback value.

Source

pub fn binding_error_with_fallback( error: BindingError, fallback: Option<T>, ) -> Self

A binding error with an optional fallback value.

Source

pub fn data_validation_error(error: BindingError) -> Self

A data validation error without a fallback value.

Source

pub fn data_validation_error_with_fallback( error: BindingError, fallback: Option<T>, ) -> Self

A data validation error with an optional fallback value.

Source

pub fn has_value(&self) -> bool

Whether the binding value carries a value (or fallback value).

Source

pub fn has_error(&self) -> bool

Whether the binding value carries an error.

Source

pub fn value_type(&self) -> BindingValueType

Source

pub fn value(&self) -> &T

The value. Panics if there is none, see has_value.

Source

pub fn error(&self) -> Option<&BindingError>

Source

pub fn into_option(self) -> Option<T>

Converts into the contained value, if any.

Source

pub fn get_value_or_default(self, default: T) -> T

Returns the value, or default if there is none.

Source

pub fn with_value(self, value: T) -> Self

Returns a binding value with the same error state and a new value. For error states this turns them into their “with fallback” variants.

Source

pub fn map<U>(self, f: impl FnOnce(T) -> U) -> BindingValue<U>

Maps the contained value, keeping the state.

Source§

impl<T: Clone> BindingValue<T>

Source

pub fn to_optional(&self) -> Option<T>

Converts the binding value to an optional value: the value (or fallback value), if there is one.

Source

pub fn get_value_or_default_option(&self) -> Option<T>

Gets the value of the binding value if present, otherwise the default value: none.

Source§

impl<T: Clone + 'static> BindingValue<T>

Source

pub fn get_value_or_default_as<TResult: Clone + 'static>( &self, ) -> Option<TResult>

Gets the value of the binding value if it is present and of type TResult, otherwise the default value: none.

Source

pub fn get_value_or_default_as_or<TResult: Clone + 'static>( &self, default_value: TResult, ) -> Option<TResult>

Gets the value of the binding value if it is present and of type TResult; none if it is present and of another type; default_value if there is no value.

Source§

impl<T: PropertyValue> BindingValue<T>

Source

pub fn to_untyped(&self) -> Option<BoxedValue>

Converts the value to untyped representation, using the unset and do-nothing markers and BindingNotification where appropriate.

§Panics

Panics if the type of the binding value is none of the kinds BindingValueType declares.

Source

pub fn from_untyped(value: Option<&BoxedValue>) -> Self

Creates a binding value from an untyped value: the unset or do-nothing marker, a BindingNotification, or a value that converts implicitly to T.

Source

pub fn from_untyped_with_type( value: Option<&BoxedValue>, target_type: ValueType, ) -> Self

Creates a binding value from an untyped value, converting the value to target_type.

A value that does not convert to target_type, or whose conversion is not a T, gives a binding error. Null converts only to a target type that has a null value of its own (a nullable form): T itself is never null here.

Trait Implementations§

Source§

impl<T: Clone> Clone for BindingValue<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for BindingValue<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display> Display for BindingValue<T>

The text of the binding value: Error: <message> for an error, the text of the value, or (null) without a value.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<Option<T>> for BindingValue<T>

Source§

fn from(value: Option<T>) -> Self

None maps to the unset state.

Source§

impl<T> From<T> for BindingValue<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq> PartialEq for BindingValue<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for BindingValue<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for BindingValue<T>

§

impl<T> !Send for BindingValue<T>

§

impl<T> !Sync for BindingValue<T>

§

impl<T> !UnwindSafe for BindingValue<T>

§

impl<T> Freeze for BindingValue<T>
where Option<T>: Freeze,

§

impl<T> Unpin for BindingValue<T>
where Option<T>: Unpin,

§

impl<T> UnsafeUnpin for BindingValue<T>
where Option<T>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.