51 releases (27 breaking)

0.29.0 Jun 7, 2020
0.27.0 Apr 15, 2020
0.14.1 Mar 31, 2020
0.5.2 Dec 28, 2019

#13 in #borrow

Download history 28/week @ 2020-11-06 57/week @ 2020-11-27 99/week @ 2020-12-04 51/week @ 2021-01-15 23/week @ 2021-02-05 223/week @ 2021-02-12

231 downloads per month


732 lines


Synchronous and recursive event system.


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.


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.


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| {
        // 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.