pub struct Graph { /* private fields */ }Expand description
Graph is dagrs’s main body.
[‘Graph’] is a network that satisfies FBP logic, provides node dependencies, and runs all of its nodes completely asynchronously
A Graph contains multiple nodes, which can be added as long as they implement the Node trait.
Each node defines specific execution logic by implementing the [Action] trait and overriding the run method.
The execution process of a Graph proceeds as follows:
- The user creates a set of nodes, each implementing the
Nodetrait. These nodes can be created programmatically or Generate auto_node using parse. - Dependencies between nodes are defined, creating a directed acyclic graph (DAG) structure.
- During execution, nodes communicate via input/output channels (
InChannelandOutChannel). These channels support both point-to-point communication (usingMPSC) and broadcasting (usingBroadcast). - After all nodes complete their execution, marking the graph as inactive.
This ensures that the
Graphcannot be executed again without resetting its state.
The Graph is designed to efficiently manage task execution with built-in fault tolerance and flexible scheduling.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn add_edge(&mut self, from_id: NodeId, all_to_ids: Vec<NodeId>)
pub fn add_edge(&mut self, from_id: NodeId, all_to_ids: Vec<NodeId>)
Adds an edge between two nodes in the Graph.
If the outgoing port of the sending node is empty and the number of receiving nodes is > 1, use the broadcast channel
An MPSC channel is used if the outgoing port of the sending node is empty and the number of receiving nodes is equal to 1
If the outgoing port of the sending node is not empty, adding any number of receiving nodes will change all relevant channels to broadcast
Sourcepub fn start(&mut self) -> Result<(), GraphError>
pub fn start(&mut self) -> Result<(), GraphError>
This function is used for the execution of a single dag.
Sourcepub fn check_loop_and_partition(&mut self) -> bool
pub fn check_loop_and_partition(&mut self) -> bool
Checks for cycles in the abstract graph, and partitions the graph into blocks.
- Groups nodes into blocks, creating a new block whenever a conditional node / loop is encountered
Returns true if the graph contains a cycle, false otherwise.
pub fn get_outputs(&self) -> HashMap<NodeId, Output>
Auto Trait Implementations§
impl !RefUnwindSafe for Graph
impl !UnwindSafe for Graph
impl Freeze for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
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
impl<T> ErasedDestructor for Twhere
T: 'static,
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