pub struct TaskGraph<T: Clone + Send + 'static> { /* private fields */ }Expand description
A directed acyclic graph of tasks with automatic parallel execution.
Tasks are added via add_task and executed via
execute. Independent tasks (those whose
dependencies are all satisfied) run concurrently on OS threads.
T must be Clone + Send + 'static so that results can be shared
between threads and stored in the result map.
Implementations§
Source§impl<T: Clone + Send + 'static> TaskGraph<T>
impl<T: Clone + Send + 'static> TaskGraph<T>
Sourcepub fn contains_task(&self, name: &str) -> bool
pub fn contains_task(&self, name: &str) -> bool
Returns true if the graph contains a task with the given name.
Sourcepub fn dependencies(&self, name: &str) -> Option<&[String]>
pub fn dependencies(&self, name: &str) -> Option<&[String]>
Get the dependency names for a task.
Sourcepub fn add_task<F>(
&mut self,
name: &str,
deps: &[&str],
func: F,
) -> TaskGraphResult<()>
pub fn add_task<F>( &mut self, name: &str, deps: &[&str], func: F, ) -> TaskGraphResult<()>
Add a task to the graph.
name: unique identifier for the task.deps: names of tasks that must complete before this one.func: closure receiving a map of completed dependency results.
§Errors
CoreError::ValueErrorifnameis already taken.CoreError::ValueErrorif any dependency name is not yet registered.CoreError::ComputationErrorif adding this task would create a cycle.
Sourcepub fn execute(self) -> TaskGraphResult<HashMap<String, T>>
pub fn execute(self) -> TaskGraphResult<HashMap<String, T>>
Execute all tasks in the graph, respecting dependencies.
Tasks at the same dependency level run concurrently on OS threads. Returns a map from task name to result.
§Errors
- If a task closure returns an error, execution continues for independent tasks but dependent tasks will not run.
- Returns the first error encountered.
Sourcepub fn execute_partial(self) -> TaskGraphResult<HashMap<String, T>>
pub fn execute_partial(self) -> TaskGraphResult<HashMap<String, T>>
Execute the graph and return only successfully completed results, ignoring failures (partial execution).
Unlike execute, this never returns an error
for task failures. Tasks with unsatisfied dependencies are silently
skipped.
Sourcepub fn execution_order(&self) -> Vec<String>
pub fn execution_order(&self) -> Vec<String>
Return a topological ordering of task names.
Useful for debugging or inspection.
Sourcepub fn execution_levels(&self) -> Vec<Vec<String>>
pub fn execution_levels(&self) -> Vec<Vec<String>>
Return task names grouped by execution level.
Tasks within the same level can execute concurrently.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for TaskGraph<T>
impl<T> !RefUnwindSafe for TaskGraph<T>
impl<T> Send for TaskGraph<T>
impl<T> !Sync for TaskGraph<T>
impl<T> Unpin for TaskGraph<T>
impl<T> UnsafeUnpin for TaskGraph<T>
impl<T> !UnwindSafe for TaskGraph<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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.