revent 0.29.0

Event system for Rust
Documentation

Synchronous and recursive event system.

Introduction

An event system is a collection of objects that can receive and send signals.

In revent we construct something called a [Node] containing an object of interest. This object can invoke objects in other nodes, which in turn can invoke other objects - including the originator - safely. This is done by suspending the &mut self to the contents of a node.

Example

use revent::Node;

let number = Node::new(123);

number.emit(|n| {
println!("{}", *n);
*n = 100;
println!("{}", *n);
});

See the documentation for [Channel] and [Slot] and [Suspend] for examples.

Intent

This library is intended to be used as a "suspendable RefCell" by a bunch of objects which wish to communicate with each other without using a central mediator object.

For instance, one can create a revent::Channel<dyn MyTrait> which contains objects of interest, where each object can inside its own handler do something along the lines of:

use revent::{Channel, Suspend};
trait MyTrait {
fn function(&mut self, channel: &Channel<dyn MyTrait>);
}

struct MyObject;
impl MyTrait for MyObject {
fn function(&mut self, channel: &Channel<dyn MyTrait>) {
// Do something...
self.suspend(|| {
channel.emit(|x| {
x.function(channel);
});
});
// Do something else...
}
}

The above allows the object to emit a signal on a channel it is part of, even calling itself recursively without mutably aliasing by suspending &mut self.