pub struct ActionRef<R, A> {
pub id: &'static str,
pub params: &'static [&'static str],
/* private fields */
}Expand description
A typed reference to one declared action of R taking input A — the
thing views bind controls to and tests apply. Generated by #[resource]
and #[derive(Effect)] as an associated constant per action
(Note::EDIT).
The key Self::key reads from it is how the framework binds a control:
it names the app, the resource kind and the action, so a control cannot
bind to an action another resource publishes, and an action a resource
stops publishing fails where it is bound rather than greying a button.
A is the action’s argument, or a tuple of its arguments in order.
Fields§
§id: &'static str§params: &'static [&'static str]Implementations§
Source§impl<R, A> ActionRef<R, A>
impl<R, A> ActionRef<R, A>
Source§impl<E: Effect, A> ActionRef<E, A>
impl<E: Effect, A> ActionRef<E, A>
Sourcepub fn spec(&self) -> Option<ActionSpec>
pub fn spec(&self) -> Option<ActionSpec>
The action this effect’s declaration publishes, as the resource that offers the vocabulary publishes it: what a control binds to without a row carrying it.
Sourcepub fn binding(
&self,
resource: impl Into<String>,
) -> Result<ActionBinding<()>, ActionBindingError>
pub fn binding( &self, resource: impl Into<String>, ) -> Result<ActionBinding<()>, ActionBindingError>
A control’s binding to this effect on resource, from its
declaration: the resource’s own address and the declared action, with
no carrier row. A nullary effect binds as a button; one taking
arguments is offered with them asked.
§Errors
The declaration publishes no such action, or it requires an argument this binding gives none.
Source§impl<R, A: Serialize> ActionRef<R, A>
impl<R, A: Serialize> ActionRef<R, A>
Sourcepub const fn new(
id: &'static str,
params: &'static [&'static str],
kind: ResourceKind,
) -> Self
pub const fn new( id: &'static str, params: &'static [&'static str], kind: ResourceKind, ) -> Self
The reference #[resource] and #[derive(Effect)] generate: action
id taking the parameters params, of the kind kind declares. The
kind is built by a const fn of a type’s name alone, so it is the same
value at every use and costs no initialisation.
Sourcepub fn on(&self, resource: impl Into<String>) -> ActionAddress
pub fn on(&self, resource: impl Into<String>) -> ActionAddress
This action as the published resource resource offers it (the
record, one of its items, or a resource a view or search hit derives
from it, by its published id): what a search hit invokes or a test
addresses through the host’s API. The action’s id comes from the
typed reference, so it cannot name one the app does not declare.
Sourcepub fn arguments(&self, input: &A) -> Result<Map<String, Value>, String>
pub fn arguments(&self, input: &A) -> Result<Map<String, Value>, String>
The JSON arguments this input binds to: a verb’s parameter struct as its fields, or positional inputs under the declared names.
Sourcepub fn with(&self, input: impl Into<A>) -> Invoke<R>
pub fn with(&self, input: impl Into<A>) -> Invoke<R>
Fully apply the input: an invocation with nothing left to supply.
A verb’s parameter struct converts from its parameters in order: one
value, or a tuple of several. An input that does not bind makes an
invocation that refuses with why (Invoke::refusal), never one
with empty arguments.
Source§impl<R, A: Serialize> ActionRef<R, A>
impl<R, A: Serialize> ActionRef<R, A>
Sourcepub fn map<I, T, F>(self, map: F) -> Mapped<R, A, F>
pub fn map<I, T, F>(self, map: F) -> Mapped<R, A, F>
Adapt a control’s input to this action’s arguments — typically to bind
the item a row stands for: Todo::SET_DONE.map(move |done| (id.clone(), done)).
Sourcepub fn try_map<I, T, F>(self, parse: F) -> TryMapped<R, A, F>
pub fn try_map<I, T, F>(self, parse: F) -> TryMapped<R, A, F>
Adapt a control’s input to this action’s arguments where the input
may not make any: parse reads the input (a draft’s text) and makes
the arguments only when it parses, through the types that refuse what
the action would refuse (NonBlank):
Tracker::CREATE.try_map(|title: String| Some(Create { title: NonBlank::parse(&title)?, .. })).
An input parse makes nothing of invokes nothing; a control bound
to a draft through it is disabled meanwhile. parse only reads: it
also runs, as the draft changes, to tell whether the control can act.
Trait Implementations§
Source§impl<R: 'static, A: Serialize + 'static, I: Into<A>> Binds<R, I> for ActionRef<R, A>
A control binds an action whose input its value converts to: a text
field binds a verb taking one String.
impl<R: 'static, A: Serialize + 'static, I: Into<A>> Binds<R, I> for ActionRef<R, A>
A control binds an action whose input its value converts to: a text
field binds a verb taking one String.
fn action_id(&self) -> &'static str
Source§fn action_key(&self) -> ActionKey
fn action_key(&self) -> ActionKey
ActionRef::key); anything else is bound as R’s own action
under R’s app and kind.impl<R, A> Copy for ActionRef<R, A>
Auto Trait Implementations§
impl<R, A> Forget for ActionRef<R, A>
impl<R, A> Freeze for ActionRef<R, A>
impl<R, A> Move for ActionRef<R, A>
impl<R, A> RefUnwindSafe for ActionRef<R, A>
impl<R, A> Send for ActionRef<R, A>
impl<R, A> Sync for ActionRef<R, A>
impl<R, A> Unpin for ActionRef<R, A>
impl<R, A> UnsafeUnpin for ActionRef<R, A>
impl<R, A> UnwindSafe for ActionRef<R, A>
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