Skip to main content

NodeId

Struct NodeId 

Source
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>

Source

pub fn id(&self) -> usize

Returns the stable numeric identifier assigned when the node was registered.

Source

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>
where T: TaskNode<Input = JoinInput<Payload>> + ?Sized, Payload: NodeArg,

Source

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>
where T: TaskNode<Input = AnyJoinInput> + ?Sized,

Source

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>

Source

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.

Source

pub fn as_dyn( self, ) -> NodeId<dyn TaskNode<Input = T::Input, Output = T::Output, Error = T::Error>>

Erases the concrete node type while keeping the node’s typed input and output contracts.

Trait Implementations§

Source§

impl<T: TaskNode + ?Sized> Clone for NodeId<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: TaskNode + ?Sized> Copy for NodeId<T>

Source§

impl<T: TaskNode + ?Sized> Debug for NodeId<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Eq + TaskNode + ?Sized> Eq for NodeId<T>

Source§

impl<T: PartialEq + TaskNode + ?Sized> PartialEq for NodeId<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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>
where PhantomData<T>: Freeze, T: ?Sized,

§

impl<T> RefUnwindSafe for NodeId<T>

§

impl<T> Send for NodeId<T>
where PhantomData<T>: Send, T: ?Sized,

§

impl<T> Sync for NodeId<T>
where PhantomData<T>: Sync, T: ?Sized,

§

impl<T> Unpin for NodeId<T>
where PhantomData<T>: Unpin, T: ?Sized,

§

impl<T> UnsafeUnpin for NodeId<T>
where PhantomData<T>: UnsafeUnpin, T: ?Sized,

§

impl<T> UnwindSafe for NodeId<T>
where PhantomData<T>: UnwindSafe, T: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> NodeArg for T
where T: Send + Sync + Debug + 'static + Clone,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more