ReporterListenerEventEventHandlerJsonPrinterProgressBarHandlerderive(Serialize)derive(Serialize)derive(Serialize)enumstructenumcurrent: u64max: u64Downloading,Installing,Running,Event -> ()impl EventHandler for JsonPrinterimpl EventHandler for ProgressBarHandlertype Event = Event;type Event = Event;fn handle(&self, event) {}fn handle(&self, event) {let json = serde_json::to_string(event);writeln!(stderr, "{}", json);match event { MyEvent::Progress(Progress { current, max }) => { self.bar.set_progress(current, max) } MyEvent::Update(update) => { self.bar.reset() }}structstructMyEventProgress(Progression)Update(Update)ProgressionUpdateAn example instance of an "Event"A communication channelbetween a transmitter (Reporter) and receiver (Listener)messages on the channel are called EventsEventHandlers act on received eventsIn the included ChannelReporter and ChannelEventListener implementations, we use a crossbeam channel to sendevents from the reporter to the listener. The listener runs in a separate thread, to keep it from blocking thethe program flow.For example, here we have a JsonPrinter which prints json serialized eventsIn the second example we have a progress bar which we update based on thereceived events. bar: ProgressBartype MyReporter = ChannelReporter<MyEvent>;fn main() { // setup let (event_sender, event_receiver) = event_channel(); let (disconnect_sender, disconnect_receiver) = disconnect_channel(); let reporter = ChannelReporter::new(event_sender, disconnect_receiver); let listener = ChannelEventListener::new(event_receiver, disconnect_sender); // spins up a second thread, so we don't block here! listener.run_handler(ProgressBarHandler::default()); // continue with regular program logic my_program_logic(&reporter);}fn my_program_logic(reporter: &MyReporter) { // ... inform user we're doing important work! reporter.report_event(MyEvent::Update(Update::Downloading)); // ... program goes brrrr work(reporter); // ... inform user about progress reporter.report_event(MyEvent::Update(Update::Installing)); // ... more work work(reporter); // ... inform user about progress reporter.report_event(MyEvent::Update(Update::Running));}fn work(reporter: &MyReporter) { thread::sleep(Duration::from_secs(1)); reporter.report_event(MyEvent::Progress(Progression { current: 50, max 100 })); thread::sleep(Duration::from_secs(1)); reporter.report_event(MyEvent::Progress(Progression { current: 100, max 100 })); thread::sleep(Duration::from_secs(1);}