Skip to main content

Binding

Struct Binding 

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

A read/write handle to a value owned elsewhere (SwiftUI’s @Binding).

Components that edit a value (a toggle, a text field) take a Binding so the caller decides where the value lives. Reads are tracked like the underlying state’s reads.

Implementations§

Source§

impl<T> Binding<T>
where T: 'static,

Source

pub fn new( get: impl Fn() -> T + 'static, set: impl Fn(T) + 'static, ) -> Binding<T>

Creates a binding from a getter and a setter.

Source

pub fn constant(value: T) -> Binding<T>
where T: Clone,

A binding that always reads value and ignores writes; useful in previews and tests.

Source

pub fn get(&self) -> T

Reads the current value through the getter.

Source

pub fn set(&self, value: T)

Writes value through the setter.

Source

pub fn update(&self, f: impl FnOnce(&mut T))

Reads the value, lets f modify it, and writes it back.

Source

pub fn map<U>( &self, get: impl Fn(&T) -> U + 'static, set: impl Fn(&mut T, U) + 'static, ) -> Binding<U>
where U: 'static,

Projects a binding onto a part of the value, e.g. one field of a struct.

Trait Implementations§

Source§

impl<T> Clone for Binding<T>

Source§

fn clone(&self) -> Binding<T>

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 for Binding<T>

Source§

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

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

impl<T> FromLive for Binding<T>
where T: FromLive + IntoLive + Clone + 'static,

Source§

fn from_live(value: Value) -> Result<Binding<T>, String>

The value as this type, or why it cannot be.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Binding<T>

§

impl<T> !Send for Binding<T>

§

impl<T> !Sync for Binding<T>

§

impl<T> !UnwindSafe for Binding<T>

§

impl<T> Freeze for Binding<T>

§

impl<T> Unpin for Binding<T>

§

impl<T> UnsafeUnpin for Binding<T>

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> AutoreleaseSafe for T
where T: ?Sized,

Source§

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

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more