Skip to content

Commit

Permalink
A minor extention to #67, expose indices (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein authored Nov 2, 2022
1 parent 6661416 commit 4cebb99
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,22 @@ impl InternalNode {
}

/// A named, user-visible node in a saga graph.
pub struct NodeEntry<'a>(&'a InternalNode);
pub struct NodeEntry<'a> {
internal: &'a InternalNode,
index: NodeIndex,
}

impl<'a> NodeEntry<'a> {
pub fn name(&self) -> &NodeName {
self.0.node_name().unwrap()
self.internal.node_name().unwrap()
}

pub fn label(&self) -> String {
self.0.label()
self.internal.label()
}

pub fn index(&self) -> NodeIndex {
self.index
}
}

Expand Down Expand Up @@ -376,12 +383,13 @@ impl<'a> Iterator for SagaDagIterator<'a> {

fn next(&mut self) -> Option<Self::Item> {
while let Some(node) = self.dag.get(self.index) {
let index = self.index;
self.index = NodeIndex::new(self.index.index() + 1);
match node {
InternalNode::Action { .. } => return Some(NodeEntry(node)),
InternalNode::Constant { .. } => return Some(NodeEntry(node)),
InternalNode::SubsagaEnd { .. } => {
return Some(NodeEntry(node))
InternalNode::Action { .. }
| InternalNode::Constant { .. }
| InternalNode::SubsagaEnd { .. } => {
return Some(NodeEntry { internal: node, index })
}
_ => (),
}
Expand Down

0 comments on commit 4cebb99

Please sign in to comment.