pub struct CommandSet { /* private fields */ }Expand description
Compiled command set built from a table of (pattern, handler) pairs.
Implementations§
Source§impl CommandSet
impl CommandSet
Sourcepub fn from_table(table: &[(&str, Handler)]) -> Result<Self, ParseError>
pub fn from_table(table: &[(&str, Handler)]) -> Result<Self, ParseError>
Build a command set from a static table of (pattern, handler) pairs.
Examples found in repository?
examples/demo.rs (line 14)
13fn main() {
14 let set = CommandSet::from_table(TABLE).expect("bad command table");
15 let stdin = std::io::stdin();
16 let mut line = String::new();
17 while stdin.read_line(&mut line).is_ok_and(|n| n > 0) {
18 match set.parse(line.trim()) {
19 Ok(cmds) => {
20 for cmd in &cmds {
21 set.dispatch(cmd);
22 }
23 }
24 Err(e) => eprintln!("ERROR: {e}"),
25 }
26 line.clear();
27 }
28}Sourcepub fn parse(&self, line: &str) -> Result<Vec<Command>, ParseError>
pub fn parse(&self, line: &str) -> Result<Vec<Command>, ParseError>
Parse an input line (which may contain multiple ;-separated commands)
into a list of Commands.
Examples found in repository?
examples/demo.rs (line 18)
13fn main() {
14 let set = CommandSet::from_table(TABLE).expect("bad command table");
15 let stdin = std::io::stdin();
16 let mut line = String::new();
17 while stdin.read_line(&mut line).is_ok_and(|n| n > 0) {
18 match set.parse(line.trim()) {
19 Ok(cmds) => {
20 for cmd in &cmds {
21 set.dispatch(cmd);
22 }
23 }
24 Err(e) => eprintln!("ERROR: {e}"),
25 }
26 line.clear();
27 }
28}Sourcepub fn dispatch(&self, cmd: &Command)
pub fn dispatch(&self, cmd: &Command)
Dispatch a parsed command to its handler.
Examples found in repository?
examples/demo.rs (line 21)
13fn main() {
14 let set = CommandSet::from_table(TABLE).expect("bad command table");
15 let stdin = std::io::stdin();
16 let mut line = String::new();
17 while stdin.read_line(&mut line).is_ok_and(|n| n > 0) {
18 match set.parse(line.trim()) {
19 Ok(cmds) => {
20 for cmd in &cmds {
21 set.dispatch(cmd);
22 }
23 }
24 Err(e) => eprintln!("ERROR: {e}"),
25 }
26 line.clear();
27 }
28}Auto Trait Implementations§
impl Freeze for CommandSet
impl RefUnwindSafe for CommandSet
impl Send for CommandSet
impl Sync for CommandSet
impl Unpin for CommandSet
impl UnsafeUnpin for CommandSet
impl UnwindSafe for CommandSet
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