Skip to content

Commit 9ed265f

Browse files
authored
feat: Add getters/setters for Bookmark. (#437)
1 parent 9ba3b17 commit 9ed265f

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

src/types.rs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ pub struct Bookmark {
1616
pub offsets: ll_bindings::tsk_bookmark_t,
1717
}
1818

19+
macro_rules! bookmark_getter {
20+
($name: ident) => {
21+
/// Get the current value
22+
pub fn $name(&self) -> $crate::SizeType {
23+
self.offsets.$name.into()
24+
}
25+
};
26+
}
27+
28+
macro_rules! bookmark_setter {
29+
($name: ident, $field: ident) => {
30+
/// Set the current value
31+
pub fn $name<I: Into<$crate::bindings::tsk_size_t>>(&mut self, value: I) {
32+
self.offsets.$field = value.into();
33+
}
34+
};
35+
}
36+
1937
impl Bookmark {
2038
pub const fn new() -> Self {
2139
Bookmark {
@@ -31,13 +49,37 @@ impl Bookmark {
3149
},
3250
}
3351
}
52+
53+
bookmark_getter!(individuals);
54+
bookmark_getter!(nodes);
55+
bookmark_getter!(edges);
56+
bookmark_getter!(migrations);
57+
bookmark_getter!(sites);
58+
bookmark_getter!(mutations);
59+
bookmark_getter!(populations);
60+
bookmark_getter!(provenances);
61+
bookmark_setter!(set_individuals, individuals);
62+
bookmark_setter!(set_nodes, nodes);
63+
bookmark_setter!(set_edges, edges);
64+
bookmark_setter!(set_migrations, migrations);
65+
bookmark_setter!(set_sites, sites);
66+
bookmark_setter!(set_mutations, mutations);
67+
bookmark_setter!(set_populations, populations);
68+
bookmark_setter!(set_provenances, provenances);
3469
}
3570

3671
#[cfg(test)]
3772
mod test {
3873

3974
use super::*;
4075

76+
macro_rules! test_set {
77+
($bmark: ident, $setter: ident, $getter: ident) => {
78+
$bmark.$setter($crate::SizeType::from(3));
79+
assert_eq!($bmark.$getter(), 3);
80+
};
81+
}
82+
4183
#[test]
4284
fn test_bookmark_mutability() {
4385
let mut b = Bookmark::new();
@@ -49,7 +91,22 @@ mod test {
4991
assert_eq!(b.offsets.mutations, 0);
5092
assert_eq!(b.offsets.populations, 0);
5193
assert_eq!(b.offsets.provenances, 0);
52-
b.offsets.nodes = 3;
53-
assert_eq!(b.offsets.nodes, 3);
94+
assert_eq!(b.nodes(), 0);
95+
assert_eq!(b.edges(), 0);
96+
assert_eq!(b.individuals(), 0);
97+
assert_eq!(b.migrations(), 0);
98+
assert_eq!(b.sites(), 0);
99+
assert_eq!(b.mutations(), 0);
100+
assert_eq!(b.populations(), 0);
101+
assert_eq!(b.provenances(), 0);
102+
103+
test_set!(b, set_nodes, nodes);
104+
test_set!(b, set_edges, edges);
105+
test_set!(b, set_migrations, migrations);
106+
test_set!(b, set_sites, sites);
107+
test_set!(b, set_mutations, mutations);
108+
test_set!(b, set_populations, populations);
109+
test_set!(b, set_provenances, provenances);
110+
test_set!(b, set_individuals, individuals);
54111
}
55112
}

0 commit comments

Comments
 (0)