Skip to content

Commit e6ea985

Browse files
committed
cool
1 parent a8e7d47 commit e6ea985

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/sys/flags.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ use crate::RawFlags;
33

44
use super::bindings::tsk_flags_t;
55

6+
use std::ops::BitXorAssign;
7+
8+
trait TstkitFlags {
9+
fn raw(&self) -> RawFlags;
10+
fn raw_mut(&mut self) -> &mut RawFlags;
11+
}
12+
13+
impl TstkitFlags for NodeFlags {
14+
fn raw(&self) -> RawFlags {
15+
self.0
16+
}
17+
fn raw_mut(&mut self) -> &mut RawFlags {
18+
&mut self.0
19+
}
20+
}
21+
622
macro_rules! impl_from_for_flag_types {
723
($flagstype: ty) => {
824
impl From<$crate::RawFlags> for $flagstype {
@@ -61,6 +77,12 @@ macro_rules! contains {
6177
};
6278
}
6379

80+
impl std::ops::BitXorAssign for NodeFlags {
81+
fn bitxor_assign(&mut self, rhs: Self) {
82+
self.0 ^= rhs.0
83+
}
84+
}
85+
6486
/// Control the behavior of table simplification.
6587
///
6688
/// Inclusion of values sets an option to `true`.
@@ -120,7 +142,8 @@ impl SimplificationOptions {
120142
/// to root, but only if they are associated with an individual
121143
/// in the individuals table.
122144
/// Cannot be specified at the same time as `KEEP_UNARY`.
123-
pub const KEEP_UNARY_IN_INDIVIDUALS: RawFlags = ll_bindings::TSK_SIMPLIFY_KEEP_UNARY_IN_INDIVIDUALS;
145+
pub const KEEP_UNARY_IN_INDIVIDUALS: RawFlags =
146+
ll_bindings::TSK_SIMPLIFY_KEEP_UNARY_IN_INDIVIDUALS;
124147

125148
flag_builder_api!(
126149
/// Update to set [`KEEP_INPUT_ROOTS`](crate::SimplificationOptions::KEEP_INPUT_ROOTS).
@@ -657,9 +680,9 @@ pub struct NodeFlags(tsk_flags_t);
657680

658681
impl NodeFlags {
659682
/// Default (empty)
660-
pub const NONE: tsk_flags_t = 0;
683+
pub const NONE: Self = Self(0);
661684
/// Node is a sample
662-
pub const IS_SAMPLE: tsk_flags_t = ll_bindings::TSK_NODE_IS_SAMPLE;
685+
pub const IS_SAMPLE: Self = Self(ll_bindings::TSK_NODE_IS_SAMPLE);
663686

664687
/// Create a new flags instance with `IS_SAMPLE` set.
665688
pub fn new_sample() -> Self {
@@ -673,7 +696,7 @@ impl NodeFlags {
673696
/// This function is called `mark_sample` to not conflict
674697
/// with [`NodeFlags::is_sample`], which predates it.
675698
pub fn mark_sample(self) -> Self {
676-
Self(self.0 | Self::IS_SAMPLE)
699+
Self(self.0 | Self::IS_SAMPLE.0)
677700
}
678701

679702
/// We do not enforce valid flags in the library.
@@ -693,8 +716,8 @@ impl NodeFlags {
693716
all!();
694717
contains!();
695718

696-
pub fn toggle(&mut self, bit: tsk_flags_t) {
697-
self.0 ^= bit
719+
pub fn toggle<I: Into<Self>>(&mut self, bit: I) {
720+
self.bitxor_assign(bit.into());
698721
}
699722

700723
pub fn remove<I>(&mut self, bit: I)

0 commit comments

Comments
 (0)