pirs-types 0.0.10

a collection of types for the PIRS project
Documentation
use std::{collections::HashMap, future::Future as Future_, pin::Pin, sync::Arc};

pub struct Pirs<'a> {
  pub state: State,
  pub exit_handler: Arc<Box<dyn Fn(i32, &mut Self) + 'a>>,
  pub logger: Box<dyn Logger + 'a>,
}

#[derive(Clone)]
pub struct Command {
  pub name: &'static str,
  #[allow(clippy::type_complexity)]
  pub handler: for<'a> fn(Pirs<'a>, Vec<String>) -> Future<'a, (Option<Pirs<'a>>, i32)>,
}

#[derive(Clone)]
pub struct State {
  pub environment: HashMap<String, String>,
  pub prompt: String,
  pub history: Vec<String>,
  pub commands: Vec<crate::Command>,
  pub last_exit_code: i32,
}

pub trait Logger: dyn_clone::DynClone {
  fn debug(&self, message: &str);

  fn info(&self, message: &str);

  fn warn(&self, message: &str);

  fn error(&self, message: &str);

  fn raw(&self, message: &str);
}

pub type Future<'a, T> = Pin<Box<dyn Future_<Output = T> + 'a>>;