pub struct Node<T: ?Sized> { /* private fields */ }
Expand description
A node in a rain
graph
Implementations§
Source§impl<T: ?Sized> Node<T>
impl<T: ?Sized> Node<T>
Sourcepub fn data(&self) -> View<RwLockReadGuard<'_, T>>
pub fn data(&self) -> View<RwLockReadGuard<'_, T>>
Read the data associated with a rain
node
Sourcepub fn try_data(&self) -> Option<View<RwLockReadGuard<'_, T>>>
pub fn try_data(&self) -> Option<View<RwLockReadGuard<'_, T>>>
Try to read the data associated with a rain
node.
Return None
if the data is currently unavailable to read, i.e. there is a write occuring
use std::ops::Deref;
use rain_lang::graph::node::{Node, Data};
let node = Node::new(Data(true));
{
let read = node.data();
assert_eq!(read.deref(), &Data(true));
let try_read = node.try_data().expect("Multiple reads are allowed!");
assert_eq!(try_read.deref(), &Data(true));
}
let mut write = node.data_mut();
*write = Data(false);
assert_eq!(write.deref(), &Data(false));
assert!(node.try_data().is_none(), "Concurrent reads and writes are not allowed!");
Sourcepub fn data_mut(&self) -> View<RwLockWriteGuard<'_, T>>
pub fn data_mut(&self) -> View<RwLockWriteGuard<'_, T>>
Mutably get the data associated with a rain
node. Note mutation is limited to
operations which will not corrupt the rain
graph (e.g. adding dependencies)
Sourcepub fn try_data_mut(&self) -> Option<View<RwLockWriteGuard<'_, T>>>
pub fn try_data_mut(&self) -> Option<View<RwLockWriteGuard<'_, T>>>
Try to mutably get the data associated with a rain
node
Return None
if the data is currently unavailable to write
use std::ops::Deref;
use rain_lang::graph::node::{Node, Data};
let node = Node::new(Data(true));
{
let mut try_write = node.try_data_mut().expect("Valid write");
*try_write = Data(false);
}
let read = node.data();
assert_eq!(read.deref(), &Data(false));
let try_read = node.try_data().expect("Multiple reads are allowed!");
assert_eq!(try_read.deref(), &Data(false));
assert!(node.try_data_mut().is_none(), "Concurrent reads and writes are not allowed!");
Source§impl<T: NodeData<Error = Infallible>> Node<T>
impl<T: NodeData<Error = Infallible>> Node<T>
Trait Implementations§
impl<T: ?Sized> Eq for Node<T>
Auto Trait Implementations§
impl<T> Freeze for Node<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for Node<T>
impl<T> Send for Node<T>
impl<T> Sync for Node<T>
impl<T> Unpin for Node<T>where
T: ?Sized,
impl<T> !UnwindSafe for Node<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more