Skip to content

Commit

Permalink
refactor: bump bitflags to 2.5.x (#630)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: flags types expose breaking changes in
bitflags public API
  • Loading branch information
molpopgen authored May 7, 2024
1 parent fb115a6 commit 9f60505
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
12 changes: 3 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ codegen-units=1
thiserror = "1.0"
libc = "0.2.154"
streaming-iterator = "0.1.5"
bitflags = "1.2.1"
bitflags = "2.5.0"
humantime = {version = "2.1.0", optional = true}
serde = {version = "1.0.199", features = ["derive"], optional = true}
serde_json = {version = "1.0.114", optional = true}
Expand Down
32 changes: 13 additions & 19 deletions src/sys/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bitflags! {
/// assert!(flags.contains(SimplificationOptions::FILTER_POPULATIONS));
/// assert!(flags.contains(SimplificationOptions::FILTER_SITES));
/// ```
#[derive(Default)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct SimplificationOptions: RawFlags {
/// Default behavior
Expand Down Expand Up @@ -229,7 +229,7 @@ bitflags! {
/// assert!(f.contains(TableClearOptions::CLEAR_TS_METADATA_SCHEMA));
/// assert!(f.contains(TableClearOptions::CLEAR_PROVENANCE);
/// ```
#[derive(Default)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TableClearOptions : RawFlags {
/// Default behavior.
Expand Down Expand Up @@ -302,7 +302,7 @@ bitflags! {
/// assert!(f.contains(TableEqualityOptions::IGNORE_PROVENANCE));
/// assert!(f.contains(TableEqualityOptions::IGNORE_METADATA));
/// ```
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TableEqualityOptions : RawFlags {
/// Default behavior.
Expand Down Expand Up @@ -351,7 +351,7 @@ bitflags! {
/// let f = TableSortOptions::default().no_check_integrity();
/// assert_eq!(f, TableSortOptions::NO_CHECK_INTEGRITY);
/// ```
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TableSortOptions : RawFlags {
/// Default behavior.
Expand Down Expand Up @@ -379,7 +379,7 @@ bitflags! {
/// let f = IndividualTableSortOptions::default();
/// assert_eq!(f, IndividualTableSortOptions::NONE);
/// ```
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct IndividualTableSortOptions : RawFlags {
/// Default behavior.
Expand Down Expand Up @@ -416,7 +416,7 @@ bitflags! {
/// let f = TreeFlags::default().no_sample_counts();
/// assert_eq!(f, TreeFlags::NO_SAMPLE_COUNTS);
/// ```
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TreeFlags: RawFlags {
/// Default behavior.
Expand Down Expand Up @@ -460,7 +460,7 @@ bitflags! {
/// when outputting a [`crate::TableCollection`], then
/// call [`crate::TableCollection::build_index`] prior to calling
/// [`crate::TableCollection::dump`].
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TableOutputOptions : RawFlags {
const NONE = 0;
Expand Down Expand Up @@ -491,7 +491,7 @@ bitflags! {
/// assert_eq!(f, TreeSequenceFlags::BUILD_INDEXES);
/// ```
///
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TreeSequenceFlags: RawFlags {
/// Default behavior
Expand Down Expand Up @@ -572,7 +572,7 @@ bitflags! {
/// let f = TableIntegrityCheckFlags::default().check_trees();
/// assert_eq!(f, TableIntegrityCheckFlags::CHECK_TREES);
/// ```
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct TableIntegrityCheckFlags: RawFlags {
/// Default behavior is a set of basic checks
Expand Down Expand Up @@ -656,7 +656,7 @@ bitflags! {
/// let f = NodeFlags::default().mark_sample();
/// assert_eq!(f, NodeFlags::IS_SAMPLE);
/// ```
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct NodeFlags : RawFlags {
/// Default (empty)
Expand Down Expand Up @@ -696,7 +696,7 @@ impl NodeFlags {
}

bitflags! {
#[derive(Default)]
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
/// Individual flags
pub struct IndividualFlags : RawFlags {
Expand Down Expand Up @@ -736,19 +736,13 @@ impl_from_for_flag_types!(TableOutputOptions);

impl From<RawFlags> for NodeFlags {
fn from(flags: RawFlags) -> Self {
// Safety: node flags can contain user-defined values.
// It is an error on the user's part to define flags
// in the first 16 bits, as per the C API docs.
unsafe { Self::from_bits_unchecked(flags) }
Self::from_bits_retain(flags)
}
}

impl From<RawFlags> for IndividualFlags {
fn from(flags: RawFlags) -> Self {
// Safety: node flags can contain user-defined values.
// It is an error on the user's part to define flags
// in the first 16 bits, as per the C API docs.
unsafe { Self::from_bits_unchecked(flags) }
Self::from_bits_retain(flags)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/example_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn clip_invalid_flags() {
assert!(simplification_flags.is_valid());

// You can skip the unsetting of invalid bits...
let simplification_flags = unsafe { SimplificationOptions::from_bits_unchecked(f) };
let simplification_flags = SimplificationOptions::from_bits_retain(f);

// ... and use this function to check.
assert!(!simplification_flags.is_valid());
Expand Down

0 comments on commit 9f60505

Please sign in to comment.