Skip to main content

ActionBinding

Struct ActionBinding 

Source
pub struct ActionBinding<I> { /* private fields */ }
Expand description

Type-safe adapter from a control’s input value to an exported action.

Construction requires the row that really exports the action (Exports) and its ActionSpec, rather than parallel string constants. Construction and emission validate the arguments against the parameters of a clone of that spec and never run its encoder, which may plan the whole action: a binding is made for each control a frame reads. The host re-resolves, validates and encodes at dispatch time because this object is convenience, not authority.

Implementations§

Source§

impl<I> ActionBinding<I>

Source

pub fn new( resource: &(impl Exports + ?Sized), spec: &ActionSpec, arguments: impl Fn(I) -> Map<String, Value> + Send + Sync + 'static, ) -> Result<Self, ActionBindingError>

Bind a typed control value to arguments for an action actually exported by resource.

§Errors

Returns ActionBindingError::ActionNotExported if spec is absent from resource.

Source

pub fn fallible( resource: &(impl Exports + ?Sized), spec: &ActionSpec, arguments: impl Fn(I) -> Result<Map<String, Value>, String> + Send + Sync + 'static, ) -> Result<Self, ActionBindingError>

Self::new for an input that may not make arguments: a value that does not serialize, a form that does not fit the parameters. Such an input is refused when the control emits it, never sent empty.

§Errors

Returns ActionBindingError::ActionNotExported if spec is absent from resource.

Source

pub fn invoke(&self, input: I) -> Result<ControlInvocation, ActionBindingError>

Produce a host-routable intent after strict parameter validation.

§Errors

Returns ActionBindingError::InvalidArguments if the mapped input violates the exported action’s parameter contract.

Source

pub fn address(&self) -> &ActionAddress

Source

pub fn shared_resource(&self) -> Option<(&str, &str, &str)>

The record a control bound here writes into for everyone in the workspace to read, as the app publishing it, the resource and its kind: a change to a shared document (a message sent into a conversation), never an effect, a view change or the person’s own record.

Source

pub fn identity(&self) -> ActionAddress

What a control bound to it does, as a window publishes it: the address the API runs it by (ResourceSpec::address_of) — so the row’s Complete names that row, and what a person presses and what a caller names at the API are one thing.

Source

pub fn map_input<J>( self, map: impl Fn(J) -> I + Send + Sync + 'static, ) -> ActionBinding<J>
where I: 'static,

The same binding for a control whose value J maps to this one’s input: a field that reports each edit for a binding that takes the text.

Source§

impl ActionBinding<()>

Source

pub fn declared( resource: impl Into<String>, spec: ActionSpec, ) -> Result<Self, ActionBindingError>

Bind a nullary control to the action spec its declaration publishes on resource, which no row carries: an effect the resource offers.

§Errors

ActionBindingError::InvalidArguments when spec requires an argument.

Source

pub fn unit( resource: &(impl Exports + ?Sized), spec: &ActionSpec, ) -> Result<Self, ActionBindingError>

Bind a nullary control to a nullary exported action.

Source

pub fn unit_for( resource: &(impl Exports + ?Sized), action_id: &str, ) -> Result<Self, ActionBindingError>

Look up the real exported spec by stable id, then create a nullary binding. Useful when the resource is assembled inline or generated.

Source

pub fn static_json( resource: &(impl Exports + ?Sized), spec: &ActionSpec, arguments: Map<String, Value>, ) -> Result<Self, ActionBindingError>

Bind a control to a fixed, strictly validated JSON argument object.

Source

pub fn static_json_for( resource: &(impl Exports + ?Sized), action_id: &str, arguments: Map<String, Value>, ) -> Result<Self, ActionBindingError>

Look up the real exported spec by id, then bind fixed JSON arguments.

Trait Implementations§

Source§

impl<I: Clone> Clone for ActionBinding<I>

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

Auto Trait Implementations§

§

impl<I> !RefUnwindSafe for ActionBinding<I>

§

impl<I> !UnwindSafe for ActionBinding<I>

§

impl<I> Forget for ActionBinding<I>

§

impl<I> Freeze for ActionBinding<I>
where Arc<dyn Fn(I) -> Result<Map<String, Value>, String> + Send + Sync>: Freeze,

§

impl<I> Move for ActionBinding<I>

§

impl<I> Send for ActionBinding<I>
where Arc<dyn Fn(I) -> Result<Map<String, Value>, String> + Send + Sync>: Send,

§

impl<I> Sync for ActionBinding<I>
where Arc<dyn Fn(I) -> Result<Map<String, Value>, String> + Send + Sync>: Sync,

§

impl<I> Unpin for ActionBinding<I>
where Arc<dyn Fn(I) -> Result<Map<String, Value>, String> + Send + Sync>: Unpin,

§

impl<I> UnsafeUnpin for ActionBinding<I>
where Arc<dyn Fn(I) -> Result<Map<String, Value>, String> + Send + Sync>: 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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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