pub struct NodeId<T: TaskNode + ?Sized> { /* private fields */ }Expand description
A typed handle to a registered node in a Task.
NodeId keeps the node’s type information so transitions can be expressed without manual
downcasts. Use NodeId::transitions_with for the common linear case,
Transition::fan_out when building static fan-out
transitions, and NodeId::join for join nodes.
Implementations§
Source§impl<T: TaskNode + ?Sized> NodeId<T>
impl<T: TaskNode + ?Sized> NodeId<T>
Sourcepub fn id(&self) -> usize
pub fn id(&self) -> usize
Returns the stable numeric identifier assigned when the node was registered.
Sourcepub fn transitions_with(&self, context: T::Input) -> MarkedTransition<T>
pub fn transitions_with(&self, context: T::Input) -> MarkedTransition<T>
Builds a typed transition to this node with the provided input.
This is the most ergonomic way to connect one node to the next in a linear task.
§Examples
use swiftide_tasks::{NodeError, Task};
let mut task = Task::<i32, i32>::new();
let start = task.register_node_fn(|input: &i32| -> Result<i32, NodeError> { Ok(*input + 1) });
let finish = task.register_node_fn(|input: &i32| -> Result<i32, NodeError> { Ok(*input * 2) });
task.starts_with(start);
task.register_transition(start, move |value| finish.transitions_with(value))?;Source§impl<T, Payload> NodeId<T>
impl<T, Payload> NodeId<T>
Sourcepub fn join(&self) -> JoinTarget<T, Payload>
pub fn join(&self) -> JoinTarget<T, Payload>
Creates a join target that waits for every branch in the fan-out group.
Fan-out branches cannot be independent task endings. To model branches that are conceptually terminal, transition each branch to a join node and finish the task from that join node.
§Examples
use swiftide_tasks::{JoinInput, NodeError, Task, Transition};
let mut task = Task::<i32, i32>::new();
let start = task.register_node_fn(|input: &i32| -> Result<i32, NodeError> { Ok(*input) });
let branch = task.register_node_fn(|input: &i32| -> Result<i32, NodeError> { Ok(*input + 1) });
let join = task.register_node_fn(|input: &JoinInput<i32>| -> Result<i32, NodeError> {
Ok(input.iter().copied().sum())
});
task.starts_with(start);
task.register_transition(start, move |value| {
Transition::fan_out(&branch, value)
.join_with(join.join())
})?;
task.register_transition(branch, join.join())?;Source§impl<T> NodeId<T>
impl<T> NodeId<T>
Sourcepub fn join_any(&self) -> AnyJoinTarget<T>
pub fn join_any(&self) -> AnyJoinTarget<T>
Creates a join target for branches that intentionally contribute mixed payload types.
Prefer NodeId::join with JoinInput<T> when all branches
contribute the same payload type.
Source§impl<T: TaskNode + 'static + ?Sized> NodeId<T>
impl<T: TaskNode + 'static + ?Sized> NodeId<T>
Sourcepub fn new(id: usize, _node: &T) -> Self
pub fn new(id: usize, _node: &T) -> Self
Creates a typed node identifier for an already-registered node.
Prefer Task::register_node when building normal task
graphs. Constructing an id manually is only correct when id refers to a node managed by
the caller’s own task-like runtime.
Trait Implementations§
impl<T: TaskNode + ?Sized> Copy for NodeId<T>
impl<T: Eq + TaskNode + ?Sized> Eq for NodeId<T>
impl<T: PartialEq + TaskNode + ?Sized> StructuralPartialEq for NodeId<T>
Auto Trait Implementations§
impl<T> Forget for NodeId<T>where
T: ?Sized,
impl<T> Freeze for NodeId<T>
impl<T> RefUnwindSafe for NodeId<T>
impl<T> Send for NodeId<T>
impl<T> Sync for NodeId<T>
impl<T> Unpin for NodeId<T>
impl<T> UnsafeUnpin for NodeId<T>
impl<T> UnwindSafe for NodeId<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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