pub struct FnCollector { /* private fields */ }Expand description
A collector made of closures.
Implementations§
Source§impl FnCollector
impl FnCollector
pub fn new(name: &str, description: &str) -> Self
pub fn snapshot(self, f: impl Fn(&Context) -> Json + 'static) -> Self
Sourcepub fn action(
self,
name: &str,
description: &str,
mutates: bool,
f: impl FnMut(&Context, &Json) -> Result<Json, String> + 'static,
) -> Self
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.
Sourcepub fn action_as(
self,
name: &str,
description: &str,
mutates: bool,
f: impl FnMut(&Context, &Json, &Origin) -> Result<Json, String> + 'static,
) -> Self
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.
Sourcepub fn agent(self, offered: bool) -> Self
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.
Sourcepub fn mutates_when(self, f: impl Fn(&Json) -> bool + 'static) -> Self
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.
Sourcepub fn destructive(self) -> Self
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.
Sourcepub fn destructive_when(self, f: impl Fn(&Json) -> bool + 'static) -> Self
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).
Sourcepub fn schema(self, schema: Json) -> Self
pub fn schema(self, schema: Json) -> Self
Sets the JSON Schema of the last action’s arguments; its example
(FnCollector::args) stays.
Sourcepub fn result_schema(self, schema: Json) -> Self
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
impl Collector for FnCollector
fn name(&self) -> &str
fn description(&self) -> &str
fn actions(&self) -> Vec<ActionSpec>
fn snapshot(&self, ctx: &Context) -> Json
Source§fn schemas(&self, action: &str) -> Schemas
fn schemas(&self, action: &str) -> Schemas
Source§fn mutates(&self, action: &str, args: &Json) -> Option<bool>
fn mutates(&self, action: &str, args: &Json) -> Option<bool>
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
fn destructive(&self, action: &str, args: &Json) -> bool
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.Auto Trait Implementations§
impl Freeze for FnCollector
impl !RefUnwindSafe for FnCollector
impl !Send for FnCollector
impl !Sync for FnCollector
impl Unpin for FnCollector
impl UnsafeUnpin for FnCollector
impl !UnwindSafe for FnCollector
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> 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