@@ -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
671674impl NodeFlags {
675+ /// Default (empty)
676+ pub const NONE : tsk_flags_t = 0 ;
677+ /// Node is a sample
678+ pub 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+ pub 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,35 @@ 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 < I > ( & self , bit : I ) -> bool
713+ where
714+ I : Into < Self > + Copy ,
715+ {
716+ bit. into ( ) . 0 == 0 || ( self . 0 & bit. into ( ) . 0 ) != 0
717+ }
718+
719+ pub fn toggle ( & mut self , bit : tsk_flags_t ) {
720+ self . 0 ^= bit
721+ }
722+
723+ pub fn remove < I > ( & mut self , bit : I )
724+ where
725+ I : Into < Self > ,
726+ {
727+ self . 0 &= !bit. into ( ) . 0
728+ }
729+ }
730+
731+ impl From < tsk_flags_t > for NodeFlags {
732+ fn from ( value : tsk_flags_t ) -> Self {
733+ Self ( value)
697734 }
698735}
699736
@@ -736,12 +773,6 @@ impl_from_for_flag_types!(IndividualTableSortOptions);
736773impl_from_for_flag_types ! ( TableIntegrityCheckFlags ) ;
737774impl_from_for_flag_types ! ( TableOutputOptions ) ;
738775
739- impl From < RawFlags > for NodeFlags {
740- fn from ( flags : RawFlags ) -> Self {
741- Self :: from_bits_retain ( flags)
742- }
743- }
744-
745776impl From < RawFlags > for IndividualFlags {
746777 fn from ( flags : RawFlags ) -> Self {
747778 Self :: from_bits_retain ( flags)
0 commit comments