use trait aliases
This commit is contained in:
parent
58b3153a81
commit
d78ea520ca
12
src/lib.rs
12
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<Malestorm>) -> Result<(), String> + 'static;
|
||||
|
||||
pub struct Malestorm<'a> {
|
||||
node: RefCell<Node>,
|
||||
io: MalestormIo,
|
||||
pub handlers: HashMap<&'a str, Box<dyn Fn(Message, Rc<Malestorm>) -> Result<(), String>>>,
|
||||
pub handlers: HashMap<&'a str, Box<dyn Handler>>,
|
||||
}
|
||||
|
||||
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<Malestorm>) -> Result<(), String> + 'a + 'static,
|
||||
) {
|
||||
pub fn register(&mut self, name: &'a str, func: impl Handler) {
|
||||
self.handlers.insert(name, Box::new(func));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user