Skip to main content

ActionRef

Struct ActionRef 

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

Source

pub const fn id(&self) -> &'static str

The action’s public id.

Source

pub const fn params(&self) -> &'static [&'static str]

The names of the action’s parameters, in order.

Source

pub const fn kind(&self) -> &ResourceKind

The resource kind that publishes the action.

Source

pub fn key(&self) -> ActionKey

The stored form of this reference — the app, resource kind and public id a control is bound to an action by, and the shape a Shortcut step, an agent’s plan or a palette entry keeps.

Source§

impl<E: Effect, A> ActionRef<E, A>

Source

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.

Source

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>

Source

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.

Source

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.

Source

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.

Source

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

pub fn try_with(&self, input: impl Into<A>) -> Result<Invoke<R>, String>

Self::with, reporting an input that does not bind at once.

Source§

impl<R, A: Serialize> ActionRef<R, A>

Source

pub fn map<I, T, F>(self, map: F) -> Mapped<R, A, F>
where F: Fn(I) -> T, T: Into<A>,

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

Source

pub fn try_map<I, T, F>(self, parse: F) -> TryMapped<R, A, F>
where F: Fn(I) -> Option<T>, T: Into<A>,

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.

Source§

impl<R, A: NoParams> ActionRef<R, A>

Source

pub fn invoke(&self) -> Invoke<R>

The invocation of a nullary action.

Source§

impl<R, P: Serialize> ActionRef<R, P>

Source

pub fn bind<V: Serialize>(&self, param: Path<P, V>, value: V) -> Bound<R>

This verb with the parameter at param (a path of its parameter struct, NewSnippet::paths().folder) bound to value.

Source

pub fn unbound(&self) -> Bound<R>

This verb with nothing bound: every parameter still asked, offered on a place as it is on the record (the terminal’s verbs on its place).

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.

Source§

fn action_id(&self) -> &'static str

Source§

fn action_key(&self) -> ActionKey

The key the action is published under — the app, resource kind and action id — which a control is bound against. A reference carries its own (ActionRef::key); anything else is bound as R’s own action under R’s app and kind.
Source§

fn arguments(&self, input: I) -> Result<Map<String, Value>, String>

The arguments input binds to. Read more
Source§

impl<R, A> Clone for ActionRef<R, A>

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<R, A> Copy for ActionRef<R, A>

Source§

impl<R, A> Debug for ActionRef<R, A>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, A> Forget for ActionRef<R, A>

§

impl<R, A> Freeze for ActionRef<R, A>
where PhantomData<fn(A) -> R>: Freeze,

§

impl<R, A> Move for ActionRef<R, A>

§

impl<R, A> RefUnwindSafe for ActionRef<R, A>
where PhantomData<fn(A) -> R>: RefUnwindSafe,

§

impl<R, A> Send for ActionRef<R, A>
where PhantomData<fn(A) -> R>: Send,

§

impl<R, A> Sync for ActionRef<R, A>
where PhantomData<fn(A) -> R>: Sync,

§

impl<R, A> Unpin for ActionRef<R, A>
where PhantomData<fn(A) -> R>: Unpin,

§

impl<R, A> UnsafeUnpin for ActionRef<R, A>
where PhantomData<fn(A) -> R>: UnsafeUnpin,

§

impl<R, A> UnwindSafe for ActionRef<R, A>
where PhantomData<fn(A) -> R>: UnwindSafe,

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