pub struct CmdBuilder { /* private fields */ }Expand description
Create a command from node-definition file and an async fn run() function.
Implementations§
Source§impl CmdBuilder
impl CmdBuilder
Sourcepub fn new(def: &str) -> Result<Self, Error>
pub fn new(def: &str) -> Result<Self, Error>
Start building command with a JSON node-definition.
Most of the time you would use include_str to get the file content and pass to this.
Sourcepub fn check_name(self, name: &str) -> Result<Self, BuilderError>
pub fn check_name(self, name: &str) -> Result<Self, BuilderError>
Check that the command name in node-definition is equal to this name, to prevent accidentally using the wrong node-definition.
Sourcepub fn permissions(self, p: Permissions) -> Self
pub fn permissions(self, p: Permissions) -> Self
Set permissions of the command.
Sourcepub fn simple_instruction_info(
self,
signature_name: &str,
) -> Result<Self, BuilderError>
pub fn simple_instruction_info( self, signature_name: &str, ) -> Result<Self, BuilderError>
Use an InstructionInfo::simple for this command.
Sourcepub fn build<T, U, Fut, F>(self, f: F) -> Box<dyn CommandTrait>where
F: Fn(CommandContext, T) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<U, CommandError>> + Send + 'static,
T: DeserializeOwned + 'static,
U: Serialize,
pub fn build<T, U, Fut, F>(self, f: F) -> Box<dyn CommandTrait>where
F: Fn(CommandContext, T) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<U, CommandError>> + Send + 'static,
T: DeserializeOwned + 'static,
U: Serialize,
Build the command, f will be used as this command’s fn run().
fmust be anasync fn(Context, Input) -> Result<Output, CommandError>.Inputmust implementDeserializeOwned.Outputmust implementSerialize.
Trait Implementations§
Source§impl Clone for CmdBuilder
impl Clone for CmdBuilder
Source§fn clone(&self) -> CmdBuilder
fn clone(&self) -> CmdBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CmdBuilder
impl RefUnwindSafe for CmdBuilder
impl Send for CmdBuilder
impl Sync for CmdBuilder
impl Unpin for CmdBuilder
impl UnwindSafe for CmdBuilder
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
Mutably borrows from an owned value. Read more