Detached

Struct Detached 

Source
pub struct Detached<Input, Error, Context, NodeType = (), NodeOutput = (), NodeError = ()> { /* private fields */ }
Expand description

Detached executes a node asynchronously and independently of the main flow.

The node is executed in a detached task using the SpawnAsync context trait and any result or error from the detached node is ignored.

This flow is useful for side-effect operations such as logging, analytics, or background triggers that should not block or influence the main execution path.

§Type Parameters

  • Input: The type of data accepted and produced by this flow.
  • Error: The type of error emitted by this flow.
  • Context: The type of context used during execution.

§Examples

use node_flow::node::{Node, NodeOutput};
use node_flow::context::{SpawnAsync, Fork};
use node_flow::flows::Detached;
use std::future::Future;

#[derive(Clone)]
struct PrintNode;

struct ExampleCtx;
impl Fork for ExampleCtx // ...
impl SpawnAsync for ExampleCtx // ...

impl<Ctx: Send> Node<u8, NodeOutput<()>, (), Ctx> for PrintNode {
    async fn run(&mut self, input: u8, _: &mut Ctx) -> Result<NodeOutput<()>, ()> {
        println!("Running detached task with input: {input}");
        Ok(NodeOutput::Ok(()))
    }
}

async fn main() {
    let mut detached = Detached::<u8, (), _>::new(PrintNode);

    let mut ctx = ExampleCtx;
    let result = detached.run(7, &mut ctx).await;
    assert_eq!(result, Ok(NodeOutput::Ok(7)));
}

Implementations§

Source§

impl<Input, Error, Context> Detached<Input, Error, Context>

Source

pub fn new<NodeType, NodeOutput, NodeError>( node: NodeType, ) -> Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: Node<Input, NodeOutput, NodeError, Context> + Clone + Send, Input: Clone + Send,

Creates a new Detached flow by wrapping the given node.

See also Detached.

§Examples
use node_flow::flows::Detached;
use node_flow::node::{Node, NodeOutput};

#[derive(Clone)]
struct BackgroundTask;
impl<Ctx: Send> Node<(), NodeOutput<()>, (), Ctx> for BackgroundTask // ...

let detached = Detached::<(), (), Ctx>::new(BackgroundTask);

Trait Implementations§

Source§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Clone for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Debug for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: Debug,

Source§

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

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

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Node<Input, NodeOutput<Input>, Error, Context> for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: Node<Input, NodeOutput, NodeError, Context> + Clone + Send + 'static, Context: SpawnAsync + Fork + Send + 'static, Input: Clone + Send + 'static,

Source§

fn run( &mut self, input: Input, context: &mut Context, ) -> impl Future<Output = Result<NodeOutput<Input>, Error>> + Send

Runs the node. Read more
Source§

fn describe(&self) -> Description

Describes this node, its type signature and other specifics. Read more

Auto Trait Implementations§

§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Freeze for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>

§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> RefUnwindSafe for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: RefUnwindSafe,

§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Send for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: Sync + Send,

§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Sync for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: Sync + Send,

§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Unpin for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>

§

impl<Input, Error, Context, NodeType, NodeOutput, NodeError> UnwindSafe for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
where NodeType: RefUnwindSafe,

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<Input, Output, Error, Context, T> BoxedNode<Input, Output, Error, Context> for T
where T: Node<Input, Output, Error, Context>,

Source§

fn run_boxed<'life0, 'life1, 'async_trait>( &'life0 mut self, input: Input, context: &'life1 mut Context, ) -> Pin<Box<dyn Future<Output = Result<Output, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Input: 'async_trait, Output: 'async_trait, Error: 'async_trait, T: 'async_trait,

Available on crate feature boxed_node only.
Runs the node. Read more
Source§

fn describe(&self) -> Description

Available on crate feature boxed_node only.
Describes this node, its type signature and other specifics. Read more
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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