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
//! Link - A doublet (source, target) pair with an index
//!
//! This module provides the core Link data structure that represents
//! a link in the doublet storage.
/// Link represents a doublet (source, target) pair with an index
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Link {
pub index: u32,
pub source: u32,
pub target: u32,
}
impl Link {
/// Creates a new link with the given index, source, and target
pub fn new(index: u32, source: u32, target: u32) -> Self {
Self {
index,
source,
target,
}
}
/// Returns true if this link is null (all zeros)
pub fn is_null(&self) -> bool {
self.index == 0 && self.source == 0 && self.target == 0
}
/// Returns true if this is a full point (self-referential link)
pub fn is_full_point(&self) -> bool {
self.index == self.source && self.source == self.target
}
/// Returns true if this link references itself from at least one side.
pub fn is_partial_point(&self) -> bool {
self.index == self.source || self.index == self.target
}
/// Formats the link for display
pub fn format(&self) -> String {
format!("({} {} {})", self.index, self.source, self.target)
}
}
/// Link type from the upstream `doublets` crate used as the Rust basis.
pub type DoubletsLink = doublets::Link<u32>;
impl From<DoubletsLink> for Link {
fn from(link: DoubletsLink) -> Self {
Self::new(link.index, link.source, link.target)
}
}
impl From<Link> for DoubletsLink {
fn from(link: Link) -> Self {
Self::new(link.index, link.source, link.target)
}
}