1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! A simple [`Edge`] type describing the outlet and inlet of source and
//! destination nodes respectively.
use crate::node;
use gantz_ca::CaHash;
use serde::{Deserialize, Serialize};
/// Describes a connection between two nodes.
#[derive(
Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Deserialize, Serialize, CaHash,
)]
pub struct Edge {
/// The output of the node at the source of this edge.
pub output: node::Output,
/// The input of the node at the destination of this edge.
pub input: node::Input,
}
impl Edge {
/// Create an edge representing a connection from the given node `Output` to
/// the given node `Input`.
pub fn new(output: node::Output, input: node::Input) -> Self {
Edge { output, input }
}
}
impl<A, B> From<(A, B)> for Edge
where
A: Into<node::Output>,
B: Into<node::Input>,
{
fn from((a, b): (A, B)) -> Self {
let output = a.into();
let input = b.into();
Edge { output, input }
}
}