Struct Task

Source
pub struct Task<Input: NodeArg, Output: NodeArg> { /* private fields */ }

Implementations§

Source§

impl<Input: NodeArg + Clone, Output: NodeArg + Clone> Task<Input, Output>

Source

pub fn new() -> Self

Source

pub fn done(&self) -> NodeId<NoopNode<Output>>

Source

pub fn transitions_to_done( &self, ) -> impl Fn(Output) -> MarkedTransitionPayload<NoopNode<Output>> + Send + Sync + 'static

Creates a transition to the done node

Source

pub fn starts_with<T: TaskNode<Input = Input> + Clone + 'static>( &mut self, node_id: NodeId<T>, )

Defines the start node of the task

Source

pub fn validate_transitions(&self) -> Result<(), TaskError>

Validates that all nodes have transitions set

§Errors

Errors if a node is missing a transition

Source

pub async fn run( &mut self, input: impl Into<Input>, ) -> Result<Option<Output>, TaskError>

Runs the task with the given input

§Errors

Errors if the task fails

Source

pub fn reset(&mut self)

Resets the task to the start node

WARN: This will lead to a type mismatch if the previous context is not the same as the input of the start node

Source

pub async fn resume(&mut self) -> Result<Option<Output>, TaskError>

Resumes the task from the current node

§Errors

Errors if the task fails

Source

pub fn current_node<T: TaskNode + 'static>(&self) -> Option<&T>

Gets the current node of the task

Source

pub fn node_at<T: TaskNode + 'static>(&self, node_id: NodeId<T>) -> Option<&T>

Gets the node at the given NodeId

Source

pub fn node_at_index<T: TaskNode + 'static>(&self, index: usize) -> Option<&T>

Gets the node at the given index

Source

pub fn register_node<T>(&mut self, node: T) -> NodeId<T>
where T: TaskNode + 'static + Clone, <T as TaskNode>::Input: Clone, <T as TaskNode>::Output: Clone,

Registers a new node in the task

Source

pub fn register_transition<'a, From, To, F>( &mut self, from: NodeId<From>, transition: F, ) -> Result<(), TaskError>
where From: TaskNode + 'static + ?Sized, To: TaskNode<Input = From::Output> + 'a + ?Sized, F: Fn(To::Input) -> MarkedTransitionPayload<To> + Send + Sync + 'static,

Registers a transition from one node to another

Note that there are various helpers and conversions for the MarkedTransitionPayload

§Errors

Errors if the node does not exist

Source

pub fn register_transition_async<'a, From, To, F>( &mut self, from: NodeId<From>, transition: F, ) -> Result<(), TaskError>
where From: TaskNode + 'static + ?Sized, To: TaskNode<Input = From::Output> + 'a + ?Sized, F: Fn(To::Input) -> Pin<Box<dyn Future<Output = MarkedTransitionPayload<To>> + Send>> + Send + Sync + 'static,

Registers a transition from one node to another asynchronously

Note that there are various helpers and conversions for the MarkedTransitionPayload

§Errors

Errors if the node does not exist

NOTE: AsyncFn traits’ returned future are not ‘Send’ and the inner type is unstable. When they are, we can update Fn to AsyncFn

Trait Implementations§

Source§

impl<Input: NodeArg, Output: NodeArg> Clone for Task<Input, Output>

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: Debug + NodeArg, Output: Debug + NodeArg> Debug for Task<Input, Output>

Source§

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

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

impl<Input: NodeArg + Clone, Output: NodeArg + Clone> Default for Task<Input, Output>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Input, Output> Freeze for Task<Input, Output>

§

impl<Input, Output> !RefUnwindSafe for Task<Input, Output>

§

impl<Input, Output> Send for Task<Input, Output>

§

impl<Input, Output> Sync for Task<Input, Output>

§

impl<Input, Output> Unpin for Task<Input, Output>
where Input: Unpin, Output: Unpin,

§

impl<Input, Output> !UnwindSafe for Task<Input, Output>

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

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

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