pirs_types/
lib.rs

1use std::{collections::HashMap, future::Future as Future_, pin::Pin, sync::Arc};
2
3pub struct Pirs<'a> {
4  pub state: State,
5  pub exit_handler: Arc<Box<dyn Fn(i32, &mut Self) + 'a>>,
6  pub logger: Box<dyn Logger + 'a>,
7}
8
9#[derive(Clone)]
10pub struct Command {
11  pub name: &'static str,
12  #[allow(clippy::type_complexity)]
13  pub handler: for<'a> fn(Pirs<'a>, Vec<String>) -> Future<'a, (Option<Pirs<'a>>, i32)>,
14}
15
16#[derive(Clone)]
17pub struct State {
18  pub environment: HashMap<String, String>,
19  pub prompt: String,
20  pub history: Vec<String>,
21  pub commands: Vec<crate::Command>,
22  pub last_exit_code: i32,
23}
24
25pub trait Logger: dyn_clone::DynClone {
26  fn debug(&self, message: &str);
27
28  fn info(&self, message: &str);
29
30  fn warn(&self, message: &str);
31
32  fn error(&self, message: &str);
33
34  fn raw(&self, message: &str);
35}
36
37pub type Future<'a, T> = Pin<Box<dyn Future_<Output = T> + 'a>>;