Skip to main content

tap/engine/
structs.rs

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