1
0

use trait aliases

This commit is contained in:
Ishan Jain 2024-01-04 01:33:34 +05:30
parent 58b3153a81
commit d78ea520ca
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27

View File

@ -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));
}