#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EdgeTarget {
Node(String),
End,
}
impl EdgeTarget {
pub fn node(name: impl Into<String>) -> Self {
Self::Node(name.into())
}
pub fn end() -> Self {
Self::End
}
pub fn is_end(&self) -> bool {
matches!(self, Self::End)
}
}
#[derive(Debug, Clone)]
pub struct Edge {
pub from: String,
pub to: EdgeTarget,
}
impl Edge {
pub fn new(from: impl Into<String>, to: EdgeTarget) -> Self {
Self {
from: from.into(),
to,
}
}
}
#[derive(Clone)]
pub struct ConditionalEdge {
pub from: String,
pub router: ConditionalRouter,
}
pub type ConditionalRouter = std::sync::Arc<dyn Fn(&str) -> EdgeTarget + Send + Sync>;
impl std::fmt::Debug for ConditionalEdge {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ConditionalEdge")
.field("from", &self.from)
.field("router", &"<fn>")
.finish()
}
}