Skip to main content

FnCollector

Struct FnCollector 

Source
pub struct FnCollector { /* private fields */ }
Expand description

A collector made of closures.

Implementations§

Source§

impl FnCollector

Source

pub fn new(name: &str, description: &str) -> Self

Source

pub fn snapshot(self, f: impl Fn(&Context) -> Json + 'static) -> Self

Source

pub fn action( self, name: &str, description: &str, mutates: bool, f: impl FnMut(&Context, &Json) -> Result<Json, String> + 'static, ) -> Self

Adds an action that does not need to know who called it.

Source

pub fn action_as( self, name: &str, description: &str, mutates: bool, f: impl FnMut(&Context, &Json, &Origin) -> Result<Json, String> + 'static, ) -> Self

Adds an action that acts as its caller: f gets the origin of the call (Origin::User from devtools, the bridge’s agent…), to run a command, write a value or answer a dialog as that caller.

Source

pub fn agent(self, offered: bool) -> Self

Whether agents may call the last action added (by default, when it does not mutate). Offer a writing action only when an agent running it cannot do what the user would not: it acts with the agent’s origin, through checks that refuse it what it may not do.

Source

pub fn mutates_when(self, f: impl Fn(&Json) -> bool + 'static) -> Self

Whether a call of the last action added mutates, from its arguments (commands.run: unless its command is read-only); its declared mutates stays what it may do at most.

Source

pub fn destructive(self) -> Self

The last action added is destructive: every call of it (Collector::destructive); an agent’s call waits for the user’s confirmation.

Source

pub fn destructive_when(self, f: impl Fn(&Json) -> bool + 'static) -> Self

Whether a call of the last action added is destructive, from its arguments (commands.run: when its command is).

Source

pub fn args(self, example: Json) -> Self

Sets the example arguments of the last action added.

Source

pub fn schema(self, schema: Json) -> Self

Sets the JSON Schema of the last action’s arguments; its example (FnCollector::args) stays.

Source

pub fn result_schema(self, schema: Json) -> Self

Sets the JSON Schema of the last action’s result.

Trait Implementations§

Source§

impl Collector for FnCollector

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn actions(&self) -> Vec<ActionSpec>

Source§

fn snapshot(&self, ctx: &Context) -> Json

Source§

fn schemas(&self, action: &str) -> Schemas

The JSON Schemas of an action’s arguments and result, when its author gives them (none by default).
Source§

fn mutates(&self, action: &str, args: &Json) -> Option<bool>

Whether this call of an action changes the application: its mutates, unless the action says per call (commands.run of a read-only command does not). None: no such action.
Source§

fn destructive(&self, action: &str, args: &Json) -> bool

Whether this call of an action destroys or discards what cannot easily be had back (commands.run of a destructive command): an agent’s call then waits for the user to confirm it (the agent socket asks). false by default, and for an unknown action.
Source§

fn call( &mut self, ctx: &Context, action: &str, args: &Json, origin: &Origin, ) -> Result<Json, String>

Runs an action for origin, who called it: an action that acts does so as its caller (writes a value, runs a command, answers a dialog).
Source§

impl Debug for FnCollector

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,