Skip to content

Commit ae50c58

Browse files
committed
start to remove bitflags
1 parent a286690 commit ae50c58

File tree

1 file changed

+74
-57
lines changed

1 file changed

+74
-57
lines changed

src/sys/flags.rs

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -625,63 +625,72 @@ impl TableIntegrityCheckFlags {
625625
=> check_trees, CHECK_TREES);
626626
}
627627

628-
bitflags! {
629-
/// Node flags
630-
///
631-
/// # Examples
632-
///
633-
/// ## Default (empty) flags
634-
///
635-
/// ```
636-
/// # use tskit::NodeFlags;
637-
/// let f = NodeFlags::default();
638-
/// assert_eq!(f, NodeFlags::NONE);
639-
/// ```
640-
///
641-
/// ## Create a sample node
642-
///
643-
/// Creating a sample node is such a common task that it is supported
644-
/// via a constructor:
645-
///
646-
/// ```
647-
/// # use tskit::NodeFlags;
648-
/// let f = NodeFlags::new_sample();
649-
/// assert_eq!(f, NodeFlags::IS_SAMPLE);
650-
/// ```
651-
///
652-
/// ## Buider API
653-
///
654-
/// These methods can be chained.
655-
///
656-
/// ```
657-
/// # use tskit::NodeFlags;
658-
/// let f = NodeFlags::default().mark_sample();
659-
/// assert_eq!(f, NodeFlags::IS_SAMPLE);
660-
/// ```
661-
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
662-
#[repr(transparent)]
663-
pub struct NodeFlags : RawFlags {
664-
/// Default (empty)
665-
const NONE = 0;
666-
/// Node is a sample
667-
const IS_SAMPLE = ll_bindings::TSK_NODE_IS_SAMPLE;
668-
}
669-
}
628+
//bitflags! {
629+
// /// Node flags
630+
// ///
631+
// /// # Examples
632+
// ///
633+
// /// ## Default (empty) flags
634+
// ///
635+
// /// ```
636+
// /// # use tskit::NodeFlags;
637+
// /// let f = NodeFlags::default();
638+
// /// assert_eq!(f, NodeFlags::NONE);
639+
// /// ```
640+
// ///
641+
// /// ## Create a sample node
642+
// ///
643+
// /// Creating a sample node is such a common task that it is supported
644+
// /// via a constructor:
645+
// ///
646+
// /// ```
647+
// /// # use tskit::NodeFlags;
648+
// /// let f = NodeFlags::new_sample();
649+
// /// assert_eq!(f, NodeFlags::IS_SAMPLE);
650+
// /// ```
651+
// ///
652+
// /// ## Buider API
653+
// ///
654+
// /// These methods can be chained.
655+
// ///
656+
// /// ```
657+
// /// # use tskit::NodeFlags;
658+
// /// let f = NodeFlags::default().mark_sample();
659+
// /// assert_eq!(f, NodeFlags::IS_SAMPLE);
660+
// /// ```
661+
// #[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
662+
// #[repr(transparent)]
663+
// pub struct NodeFlags : RawFlags {
664+
// /// Default (empty)
665+
// const NONE = 0;
666+
// /// Node is a sample
667+
// const IS_SAMPLE = ll_bindings::TSK_NODE_IS_SAMPLE;
668+
// }
669+
//}
670+
671+
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
672+
pub struct NodeFlags(tsk_flags_t);
670673

671674
impl NodeFlags {
675+
/// Default (empty)
676+
const NONE: tsk_flags_t = 0;
677+
/// Node is a sample
678+
const IS_SAMPLE: tsk_flags_t = ll_bindings::TSK_NODE_IS_SAMPLE;
679+
672680
/// Create a new flags instance with `IS_SAMPLE` set.
673681
pub fn new_sample() -> Self {
674682
Self::default().mark_sample()
675683
}
676684

677-
flag_builder_api!(
678-
/// Set [`IS_SAMPLE`](crate::NodeFlags::IS_SAMPLE)
679-
///
680-
/// # Note
681-
///
682-
/// This function is called `mark_sample` to not conflict
683-
/// with [`NodeFlags::is_sample`], which predates it.
684-
=> mark_sample, IS_SAMPLE);
685+
/// Set [`IS_SAMPLE`](crate::NodeFlags::IS_SAMPLE)
686+
///
687+
/// # Note
688+
///
689+
/// This function is called `mark_sample` to not conflict
690+
/// with [`NodeFlags::is_sample`], which predates it.
691+
fn mark_sample(self) -> Self {
692+
Self(self.0 | Self::IS_SAMPLE)
693+
}
685694

686695
/// We do not enforce valid flags in the library.
687696
/// This function will return `true` if any bits
@@ -693,7 +702,21 @@ impl NodeFlags {
693702
/// Returns `true` if flags contains `IS_SAMPLE`,
694703
/// and `false` otherwise.
695704
pub fn is_sample(&self) -> bool {
696-
self.contains(NodeFlags::IS_SAMPLE)
705+
self.contains(Self::IS_SAMPLE)
706+
}
707+
708+
pub fn bits(&self) -> tsk_flags_t {
709+
self.0
710+
}
711+
712+
pub fn contains(&self, bit: tsk_flags_t) -> bool {
713+
(self.0 & bit) != 0
714+
}
715+
}
716+
717+
impl From<tsk_flags_t> for NodeFlags {
718+
fn from(value: tsk_flags_t) -> Self {
719+
Self(value)
697720
}
698721
}
699722

@@ -736,12 +759,6 @@ impl_from_for_flag_types!(IndividualTableSortOptions);
736759
impl_from_for_flag_types!(TableIntegrityCheckFlags);
737760
impl_from_for_flag_types!(TableOutputOptions);
738761

739-
impl From<RawFlags> for NodeFlags {
740-
fn from(flags: RawFlags) -> Self {
741-
Self::from_bits_retain(flags)
742-
}
743-
}
744-
745762
impl From<RawFlags> for IndividualFlags {
746763
fn from(flags: RawFlags) -> Self {
747764
Self::from_bits_retain(flags)

0 commit comments

Comments
 (0)