[][src]Struct revent::Node

pub struct Node<T: ?Sized> { /* fields omitted */ }

Node containing arbitrary data.

Ensures that no double-mutable borrows exist and allows the contained item to Suspend itself.

Node is fundamentally the same as RefCell, but does one more thing: it allows suspension of the last emitted node by using its &mut. Suspending allows the node to be reborrowed without aliasing.

Implementations

impl<T> Node<T>[src]

pub fn new(item: T) -> Self[src]

Create a new node.

pub fn new_with_trace(item: T, trace: impl Fn(usize) + 'static) -> Self[src]

Create a new node with a tracing function.

The trace function is called with the current indentation value. It can be used to log calls to nodes and see how various nodes call upon other nodes.

Requires the trace feature to be enabled to actually use the trace function.

impl<T: ?Sized> Node<T>[src]

pub fn emit<F: FnOnce(&mut T) -> R, R>(&self, handler: F) -> R[src]

Acquire a &mut to the contents of the node and allow it to Suspend itself.

use revent::Node;

let node = Node::new(123);

node.emit(|x| {
    *x = 456;
    println!("{}", x);
});

Panics

Panics if the node has already been accessed without being suspended.

use revent::Node;
let node = Node::new(123);

node.emit(|_| {
    node.emit(|_| {});
});

The mitigation is to call suspend on the emit lambda argument.

use revent::{Node, Suspend};
let node = Node::new(123);

node.emit(|x| {
    x.suspend(|| {
        node.emit(|_| {});
    });
});

pub fn ptr_eq(this: &Self, other: &Self) -> bool[src]

Returns true if two Nodes point to the same allocation.

Trait Implementations

impl<T> Clone for Node<T>[src]

impl<T: ?Sized, U> CoerceUnsized<Node<U>> for Node<T> where
    T: Unsize<U>,
    U: ?Sized
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Node<T>

impl<T> !Send for Node<T>

impl<T> !Sync for Node<T>

impl<T: ?Sized> Unpin for Node<T>

impl<T> !UnwindSafe for Node<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Suspend for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.