Skip to main content

tap/engine/
structs.rs

1use crate::argsparsing::ArgsP;
2use std::{collections::HashMap, rc::Rc};
3
4pub type ErrorType = Result<(), Box<dyn std::error::Error>>;
5
6pub type RawHandlerType = dyn Fn(&mut Engine<'_>, &[&str]) -> ErrorType;
7pub type HandlerType = Rc<RawHandlerType>;
8pub type SubHandlerType = fn(&[&str]) -> ErrorType;
9
10pub type CmdInfoCmd<'a> = CmdInfo<'a, HandlerType>;
11pub type CmdInfoSubcmd<'a> = CmdInfo<'a, SubHandlerType>;
12
13#[derive(PartialEq, Clone)]
14pub struct CmdInfo<'a, H> {
15    pub handler: H,
16    pub required: Vec<&'a str>,
17    pub optional: Vec<&'a str>,
18    pub unlimited: bool,
19    pub docs: &'static str,
20}
21
22pub type CmdMap<'a> = HashMap<&'a str, CmdInfoCmd<'a>>;
23pub type SubCmdsMap<'a> = HashMap<&'a str, CmdInfoSubcmd<'a>>;
24pub type BasicHandler<'a> = Option<CmdInfo<'a, HandlerType>>;
25
26pub struct Engine<'a> {
27    pub args_p: &'a mut ArgsP,
28    pub cmds: CmdMap<'a>,
29    pub subcmds: SubCmdsMap<'a>,
30    pub basic_handler: BasicHandler<'a>,
31    pub about: String,
32}