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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Generic ID types for user-defined node, pin, and edge identification.
//!
//! Nodes, pins, and edges carry the user's own id type directly; the library
//! never keeps a separate id-to-index map. These traits just collect the bounds
//! the widget needs on those id types.
use Debug;
use Hash;
/// Trait for user-defined node identifiers.
///
/// Implement this trait on your own types to use them as node IDs:
/// ```rust
/// use iced_nodegraph::NodeId;
///
/// #[derive(Clone, Debug, PartialEq, Eq, Hash)]
/// enum MyNodeId {
/// Input,
/// Process,
/// Output,
/// }
///
/// impl NodeId for MyNodeId {}
/// ```
/// Trait for user-defined pin identifiers.
///
/// Pins are identified within the context of a node, so you typically
/// use a per-node-type enum:
/// ```rust
/// use iced_nodegraph::PinId;
///
/// #[derive(Clone, Debug, PartialEq, Eq, Hash)]
/// enum MathNodePins {
/// InputA,
/// InputB,
/// Output,
/// }
///
/// impl PinId for MathNodePins {}
/// ```
/// Trait for user-defined edge identifiers.
///
/// Edges carry their own id (e.g. a database key), symmetric to nodes:
/// ```rust
/// use iced_nodegraph::EdgeId;
///
/// #[derive(Clone, Debug, PartialEq, Eq, Hash)]
/// struct MyEdgeId(u64);
///
/// impl EdgeId for MyEdgeId {}
/// ```
// Blanket implementations for common types
// `()` is the default edge id: "this edge has no id". Nodes and pins always need
// a real id, so `()` implements only `EdgeId`.
// UUID support would require the uuid crate as a dependency
// Users can implement the traits for uuid::Uuid in their own code