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>
impl<I> ActionBinding<I>
Sourcepub fn new(
resource: &(impl Exports + ?Sized),
spec: &ActionSpec,
arguments: impl Fn(I) -> Map<String, Value> + Send + Sync + 'static,
) -> Result<Self, ActionBindingError>
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.
Sourcepub fn fallible(
resource: &(impl Exports + ?Sized),
spec: &ActionSpec,
arguments: impl Fn(I) -> Result<Map<String, Value>, String> + Send + Sync + 'static,
) -> Result<Self, ActionBindingError>
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.
Sourcepub fn invoke(&self, input: I) -> Result<ControlInvocation, ActionBindingError>
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.
pub fn address(&self) -> &ActionAddress
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.
Sourcepub fn identity(&self) -> ActionAddress
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§impl ActionBinding<()>
impl ActionBinding<()>
Sourcepub fn declared(
resource: impl Into<String>,
spec: ActionSpec,
) -> Result<Self, ActionBindingError>
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.
Sourcepub fn unit(
resource: &(impl Exports + ?Sized),
spec: &ActionSpec,
) -> Result<Self, ActionBindingError>
pub fn unit( resource: &(impl Exports + ?Sized), spec: &ActionSpec, ) -> Result<Self, ActionBindingError>
Bind a nullary control to a nullary exported action.
Sourcepub fn unit_for(
resource: &(impl Exports + ?Sized),
action_id: &str,
) -> Result<Self, ActionBindingError>
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.
Sourcepub fn static_json(
resource: &(impl Exports + ?Sized),
spec: &ActionSpec,
arguments: Map<String, Value>,
) -> Result<Self, ActionBindingError>
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.
Sourcepub fn static_json_for(
resource: &(impl Exports + ?Sized),
action_id: &str,
arguments: Map<String, Value>,
) -> Result<Self, ActionBindingError>
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§
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>
impl<I> Move for ActionBinding<I>
impl<I> Send for ActionBinding<I>
impl<I> Sync for ActionBinding<I>
impl<I> Unpin for ActionBinding<I>
impl<I> UnsafeUnpin for ActionBinding<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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