pub trait Command {
fn event(
&self,
context: &mut Context<'_>,
args: &mut Tokenizer<'_>
) -> Result<()>;
fn query(
&self,
context: &mut Context<'_>,
args: &mut Tokenizer<'_>,
response: &mut ResponseUnit<'_>
) -> Result<()>;
fn help(&self, _response: &mut ResponseUnit<'_>) { ... }
fn meta(&self) -> CommandTypeMeta { ... }
}
Expand description
This trait implements a command with optional event/query operations.
Example
use scpi::prelude::*;
use scpi::error::Result;
struct MyCommand {
//...
}
// Implement Command for MyCommand
impl Command for MyCommand {
fn event(&self,context: &mut Context, args: &mut Tokenizer) -> Result<()> {
//Read a optional argument x
if let Some(x) = args.next_data(true)? {
// Non-optional argument y if x is present
let y = args.next_data(false)?.unwrap();
// Do stuff with x and y...
}else{
// Do stuff with neither x or y...
}
//I'm good thank you
Ok(())
}
fn query(&self,context: &mut Context, args: &mut Tokenizer, response: &mut ResponseUnit) -> Result<()> {
Err(ErrorCode::UndefinedHeader.into())//Query not allowed
}
}
Required Methods
Called when the event form is used