rsdiff_graphs/scg/
edge.rs

1/*
2    Appellation: edge <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use crate::Id;
6use crate::grad::GradientId;
7
8#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
9#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize,))]
10pub struct Edge<T> {
11    id: Option<GradientId<T>>,
12    data: T,
13}
14
15impl<T> Edge<T> {
16    pub fn new(data: T, id: Option<GradientId<T>>) -> Self {
17        Self { data, id }
18    }
19
20    pub fn constant(data: T) -> Self {
21        Self { data, id: None }
22    }
23
24    pub fn data(&self) -> &T {
25        &self.data
26    }
27
28    pub fn data_mut(&mut self) -> &mut T {
29        &mut self.data
30    }
31
32    pub fn id(&self) -> Option<&GradientId<T>> {
33        self.id.as_ref()
34    }
35
36    pub fn input(&self) -> Option<Id> {
37        self.id().map(|id| **id)
38    }
39}