diff --git a/src/lib.rs b/src/lib.rs index ab07bc3..c587b50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(trait_alias)] + pub mod types; use crate::types::Message; @@ -10,10 +12,12 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; +pub trait Handler = Fn(Message, Rc) -> Result<(), String> + 'static; + pub struct Malestorm<'a> { node: RefCell, io: MalestormIo, - pub handlers: HashMap<&'a str, Box) -> Result<(), String>>>, + pub handlers: HashMap<&'a str, Box>, } struct Node { @@ -130,11 +134,7 @@ impl<'a> Malestorm<'a> { format!("{}_{}", s1, s2) } - pub fn register( - &mut self, - name: &'a str, - func: impl Fn(Message, Rc) -> Result<(), String> + 'a + 'static, - ) { + pub fn register(&mut self, name: &'a str, func: impl Handler) { self.handlers.insert(name, Box::new(func)); }