[][src]Trait revent::Anchor

pub trait Anchor where
    Self: Sized
{ fn manager(&self) -> &Rc<RefCell<Manager>>; fn subscribe<R, T, F>(&mut self, create: F) -> Rc<RefCell<T>>
    where
        T: Node<Self, R>,
        F: FnOnce(R) -> T
, { ... }
fn unsubscribe<T, R>(&mut self, input: &Rc<RefCell<T>>)
    where
        T: Node<Self, R>
, { ... } }

A collection of slots to which Nodes can subscribe.

Anchors must be organized by a Manager, this is done by implementing a data structure containing various slots together with this trait.

A typical implementation may look like this:

use revent::{Anchor, Manager, Slot};
use std::{cell::RefCell, rc::Rc};

struct MyAnchor {
    a: Slot<()>,
    b: Slot<()>,
    // more slots...
    manager: Rc<RefCell<Manager>>,
}

impl Anchor for MyAnchor {
    fn manager(&self) -> &Rc<RefCell<Manager>> {
        &self.manager
    }
}

Required methods

fn manager(&self) -> &Rc<RefCell<Manager>>

Get the Manager of this anchor.

Loading content...

Provided methods

fn subscribe<R, T, F>(&mut self, create: F) -> Rc<RefCell<T>> where
    T: Node<Self, R>,
    F: FnOnce(R) -> T, 

Add a node to this anchor.

Uses Node::register_listens to figure out which slots to attach to. Node::register_emits is used to construct a struct that is given to create.

fn unsubscribe<T, R>(&mut self, input: &Rc<RefCell<T>>) where
    T: Node<Self, R>, 

Remove a node from this anchor.

Uses Node::register_listens to figure out which slots to detach from.

Loading content...

Implementors

Loading content...