#![no_std]
pub use phf;
pub type CommandFn<T> = fn(&FI<T>,&mut T, &[&str]);
pub struct FI<T: 'static> {
functions: &'static phf::Map<&'static str, CommandFn<T>>,
}
impl<T: 'static> FI<T> {
#[inline(always)]
pub const fn new(inner: &'static phf::Map<&'static str, CommandFn<T>>) -> Self {
Self { functions: inner }
}
#[inline(always)]
pub fn interpret(&self, command_et_args: &[&str], input: &mut T) -> bool {
if let Some((cmd, args)) = command_et_args.split_first() {
if let Some(&inner_function) = self.functions.get(cmd) {
inner_function(self,input, args);
return true;
}
}
false
}
}