[−][src]Struct revent::Slot
List of Nodes to a signal T
.
A slot
is a list in which one can store node handles.
use revent::{Anchor, Grapher, Manager, Node, Slot}; use std::{cell::RefCell, rc::Rc}; trait BasicSignal { fn basic(&mut self); } struct MyAnchor { basic_slot: Slot<dyn BasicSignal>, mng: Manager, } impl MyAnchor { fn new() -> Self { let mng = Manager::new(); Self { basic_slot: Slot::new("basic_slot", &mng), mng, } } } impl Anchor for MyAnchor { fn manager(&self) -> &Manager { &self.mng } } // --- struct MyNode; impl Node<MyAnchor, ()> for MyNode { fn register_emits(_: &MyAnchor) -> () { () } fn register_listens(hub: &mut MyAnchor, item: Rc<RefCell<Self>>) { hub.basic_slot.register(item); } const NAME: &'static str = "MyNode"; } impl BasicSignal for MyNode { fn basic(&mut self) { println!("Hello from MyNode::basic"); } } // --- let mut hub = MyAnchor::new(); let item = hub.subscribe(|_| MyNode); hub.basic_slot.emit(|x| x.basic()); hub.unsubscribe(&item); Grapher::new(hub.manager()).graph_to_file("target/slot-example.png").unwrap();
Methods
impl<T: ?Sized> Slot<T>
[src]
pub fn new(name: &'static str, manager: &Manager) -> Self
[src]
Create a new slot object.
The manager is used to organize multiple single/slot objects and to ensure that there are no recursive (double mutable borrow) signal chains.
name
is used for error reporting and graph generation in Manager.
pub fn emit<F>(&mut self, caller: F) where
F: FnMut(&mut T),
[src]
F: FnMut(&mut T),
Emit a signal on this signal slot.
pub fn emit_short<F>(&mut self, caller: F) where
F: FnMut(&mut T) -> bool,
[src]
F: FnMut(&mut T) -> bool,
Continue emitting only if the caller returns true
. Stops if false
.
pub fn sort_by<F>(&mut self, compare: F) where
F: FnMut(&T, &T) -> Ordering,
[src]
F: FnMut(&T, &T) -> Ordering,
Sort the nodes to this slot.
pub fn register(&mut self, item: Rc<RefCell<T>>)
[src]
Add or remove a subscriber object to this slot.
The action taken depends on whether Anchor::subscribe or Anchor::unsubscribe was called.
When adding: pushes the item to the end of the list. See sort_by if a different order is
desired.
When removing: find
s the first matching instance and removes it.
Panics
Panics if called from Anchor::unsubscribe while not being registered.
Panics if called more than once for the same object from within Anchor::subscribe.
Trait Implementations
impl<T: ?Sized> Clone for Slot<T>
[src]
fn clone(&self) -> Self
[src]
Cloning is only valid from within an Anchor::subscribe context.
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: ?Sized> Debug for Slot<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Slot<T>
impl<T> !Send for Slot<T>
impl<T> !Sync for Slot<T>
impl<T: ?Sized> Unpin for Slot<T>
impl<T> !UnwindSafe for Slot<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,