Skip to main content

neco_nodegraph/
edge.rs

1use crate::id::{EdgeId, NodeId, PortId};
2
3/// A directed connection between two node ports.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct Edge<E> {
6    id: EdgeId,
7    from: (NodeId, PortId),
8    to: (NodeId, PortId),
9    payload: E,
10}
11
12impl<E> Edge<E> {
13    /// Creates an edge from two endpoint ports and a payload.
14    pub fn new(id: EdgeId, from: (NodeId, PortId), to: (NodeId, PortId), payload: E) -> Self {
15        Self {
16            id,
17            from,
18            to,
19            payload,
20        }
21    }
22
23    /// Returns the edge identifier.
24    pub const fn id(&self) -> EdgeId {
25        self.id
26    }
27
28    /// Returns the source endpoint.
29    pub fn from(&self) -> &(NodeId, PortId) {
30        &self.from
31    }
32
33    /// Returns the destination endpoint.
34    pub fn to(&self) -> &(NodeId, PortId) {
35        &self.to
36    }
37
38    /// Returns the stored payload.
39    pub fn payload(&self) -> &E {
40        &self.payload
41    }
42
43    /// Returns mutable access to the stored payload.
44    pub fn payload_mut(&mut self) -> &mut E {
45        &mut self.payload
46    }
47}