Elegant Rust with proc macros
When writing immediate mode (egui) applications it comes to me quickly that nigh all logic computations should be done off the UI thread. There are many ways to approach it, however as a fan of eve...

Source: DEV Community
When writing immediate mode (egui) applications it comes to me quickly that nigh all logic computations should be done off the UI thread. There are many ways to approach it, however as a fan of event-based systems sooner or later I implement some kind of event handling. The pattern is almost the same with minor differences and looks like this: #[derive(Clone)] pub struct ProcessorConfig { pub id: String } #[derive(Clone)] pub struct TaskResult { pub success: bool } pub struct State { pub active_tasks: Vec<u32> } #[derive(Clone)] pub enum Event { ProcessorStart { config: ProcessorConfig }, ProcessorStop, LongRunningTask { id: u32 }, LongRunningTaskComplete { task_result: TaskResult }, } struct EventHandler { state: Arc<RwLock<State>>, tx: tokio::mpsc::Sender<Event>, } impl EventHandler { fn handle(&self, event: Event, event_queue: &mut VecDeque<Event>) { use Event::*; match event { ProcessorStart { .. } => self.process_processor_start(event, even