Skip to main content

Binding

Struct Binding 

Source
pub struct Binding<T: 'static> {
    pub read: ReadSignal<T>,
    /* private fields */
}
Expand description

A reactive, two-way binding to one field-shaped value.

§Interaction boundaries

Binding::commit and Binding::focus_exit report independent facts:

  • Commit is the widget-defined end of one interaction unit. A switch click or slider release can commit while the control remains focused.
  • Focus Exit means focus left the widget’s complete logical focus scope. An unchanged native text input can report Focus Exit without committing a value change.

§Native control example

A switch click can call write, then commit, while focus remains on the switch. A later departure from the switch calls focus_exit. An unchanged text input that loses focus can call only focus_exit because there was no value interaction to commit.

§Compound-widget example

For a compound widget, the logical focus scope includes its owned controls and popup or portal content. Moving focus from a combobox trigger into its popup does not report Focus Exit. When a selection writes and commits before focus leaves that complete scope, report the write, then Commit, then Focus Exit.

Equality compares the binding’s producer-defined identity. Equal bindings are guaranteed to represent interchangeable read, write, Commit, and Focus Exit behavior; producers may conservatively return unequal bindings when they cannot prove that interchangeability.

Fields§

§read: ReadSignal<T>

The binding’s reactive value.

Implementations§

Source§

impl<T: 'static> Binding<T>

Source

pub fn new( read: ReadSignal<T>, write: Callback<(T, ChangeOrigin)>, commit: Callback<()>, ) -> Self

Creates a binding identified by its exact read, write, and commit handles.

Focus Exit is a no-op unless replaced with Binding::with_focus_exit or Binding::with_focus_exit_using_identity.

Source

pub fn new_with_identity<I>( read: ReadSignal<T>, write: Callback<(T, ChangeOrigin)>, commit: Callback<()>, identity: I, ) -> Self
where I: PartialEq + 'static,

Creates a binding with a producer-defined comparable identity.

Equal identities must always represent interchangeable read, write, and commit behavior. This constructor installs no-op Focus Exit behavior, so that behavior is interchangeable as well. Producers that cannot prove interchangeability should use Binding::new instead.

Source

pub fn with_focus_exit(self, focus_exit: Callback<()>) -> Self

Adds the callback invoked when focus leaves the widget’s complete logical focus scope.

This builder also incorporates the callback into binding identity, preserving the guarantee that equal bindings have interchangeable Focus Exit behavior. It does not alter Commit or imply any form-library blur, touched, or validation semantics.

Source

pub fn with_focus_exit_using_identity(self, focus_exit: Callback<()>) -> Self

Adds Focus Exit behavior covered by the binding’s existing comparable identity.

Unlike Binding::with_focus_exit, this builder does not incorporate the callback’s allocation identity. Calling it asserts that bindings with equal existing identities also have interchangeable Focus Exit behavior, in addition to interchangeable read, write, and Commit behavior. Producers that cannot prove this must use Binding::with_focus_exit instead.

This builder does not alter Commit or imply any form-library blur, touched, or validation semantics.

Source

pub fn write(&self, value: T, origin: ChangeOrigin)

Writes a value and preserves where the change originated.

Source

pub fn commit(&self)

Reports the widget-defined end of one interaction unit.

Source

pub fn focus_exit(&self)

Reports that focus left the widget’s complete logical focus scope.

This is independent from Binding::commit. Widgets are responsible for defining their complete scope, including owned child controls and popup or portal content, and for suppressing reports while focus moves within it.

Source

pub fn into_trio(self) -> BindingPropTrio<T>

Decomposes this binding into the dependency-free widget prop contract.

The lower-level on_change callback has no origin parameter, so its writes are user writes.

Trait Implementations§

Source§

impl<T: 'static> Clone for Binding<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 + 'static> Debug for Binding<T>

Source§

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

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

impl<T: 'static> From<(ReadSignal<T>, Callback<T>)> for Binding<T>

Source§

fn from((read, on_change): (ReadSignal<T>, Callback<T>)) -> Self

Converts to this type from the input type.
Source§

impl<T: 'static> From<Binding<T>> for BindingPropTrio<T>

Source§

fn from(binding: Binding<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: 'static> From<Binding<T>> for FieldContext

Source§

fn from(binding: Binding<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: 'static> From<Signal<T>> for Binding<T>

Source§

fn from(signal: Signal<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: 'static> From<T> for Binding<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: 'static> PartialEq for Binding<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

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> 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> 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> DependencyElement for T
where T: 'static + PartialEq + Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
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, 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, <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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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