Skip to content

Commit 9f60505

Browse files
authored
refactor: bump bitflags to 2.5.x (#630)
BREAKING CHANGE: flags types expose breaking changes in bitflags public API
1 parent fb115a6 commit 9f60505

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

Cargo.lock

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ codegen-units=1
2020
thiserror = "1.0"
2121
libc = "0.2.154"
2222
streaming-iterator = "0.1.5"
23-
bitflags = "1.2.1"
23+
bitflags = "2.5.0"
2424
humantime = {version = "2.1.0", optional = true}
2525
serde = {version = "1.0.199", features = ["derive"], optional = true}
2626
serde_json = {version = "1.0.114", optional = true}

src/sys/flags.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bitflags! {
7171
/// assert!(flags.contains(SimplificationOptions::FILTER_POPULATIONS));
7272
/// assert!(flags.contains(SimplificationOptions::FILTER_SITES));
7373
/// ```
74-
#[derive(Default)]
74+
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7575
#[repr(transparent)]
7676
pub struct SimplificationOptions: RawFlags {
7777
/// Default behavior
@@ -229,7 +229,7 @@ bitflags! {
229229
/// assert!(f.contains(TableClearOptions::CLEAR_TS_METADATA_SCHEMA));
230230
/// assert!(f.contains(TableClearOptions::CLEAR_PROVENANCE);
231231
/// ```
232-
#[derive(Default)]
232+
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
233233
#[repr(transparent)]
234234
pub struct TableClearOptions : RawFlags {
235235
/// Default behavior.
@@ -302,7 +302,7 @@ bitflags! {
302302
/// assert!(f.contains(TableEqualityOptions::IGNORE_PROVENANCE));
303303
/// assert!(f.contains(TableEqualityOptions::IGNORE_METADATA));
304304
/// ```
305-
#[derive(Default)]
305+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
306306
#[repr(transparent)]
307307
pub struct TableEqualityOptions : RawFlags {
308308
/// Default behavior.
@@ -351,7 +351,7 @@ bitflags! {
351351
/// let f = TableSortOptions::default().no_check_integrity();
352352
/// assert_eq!(f, TableSortOptions::NO_CHECK_INTEGRITY);
353353
/// ```
354-
#[derive(Default)]
354+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
355355
#[repr(transparent)]
356356
pub struct TableSortOptions : RawFlags {
357357
/// Default behavior.
@@ -379,7 +379,7 @@ bitflags! {
379379
/// let f = IndividualTableSortOptions::default();
380380
/// assert_eq!(f, IndividualTableSortOptions::NONE);
381381
/// ```
382-
#[derive(Default)]
382+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
383383
#[repr(transparent)]
384384
pub struct IndividualTableSortOptions : RawFlags {
385385
/// Default behavior.
@@ -416,7 +416,7 @@ bitflags! {
416416
/// let f = TreeFlags::default().no_sample_counts();
417417
/// assert_eq!(f, TreeFlags::NO_SAMPLE_COUNTS);
418418
/// ```
419-
#[derive(Default)]
419+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
420420
#[repr(transparent)]
421421
pub struct TreeFlags: RawFlags {
422422
/// Default behavior.
@@ -460,7 +460,7 @@ bitflags! {
460460
/// when outputting a [`crate::TableCollection`], then
461461
/// call [`crate::TableCollection::build_index`] prior to calling
462462
/// [`crate::TableCollection::dump`].
463-
#[derive(Default)]
463+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
464464
#[repr(transparent)]
465465
pub struct TableOutputOptions : RawFlags {
466466
const NONE = 0;
@@ -491,7 +491,7 @@ bitflags! {
491491
/// assert_eq!(f, TreeSequenceFlags::BUILD_INDEXES);
492492
/// ```
493493
///
494-
#[derive(Default)]
494+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
495495
#[repr(transparent)]
496496
pub struct TreeSequenceFlags: RawFlags {
497497
/// Default behavior
@@ -572,7 +572,7 @@ bitflags! {
572572
/// let f = TableIntegrityCheckFlags::default().check_trees();
573573
/// assert_eq!(f, TableIntegrityCheckFlags::CHECK_TREES);
574574
/// ```
575-
#[derive(Default)]
575+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
576576
#[repr(transparent)]
577577
pub struct TableIntegrityCheckFlags: RawFlags {
578578
/// Default behavior is a set of basic checks
@@ -656,7 +656,7 @@ bitflags! {
656656
/// let f = NodeFlags::default().mark_sample();
657657
/// assert_eq!(f, NodeFlags::IS_SAMPLE);
658658
/// ```
659-
#[derive(Default)]
659+
#[derive(Default,Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
660660
#[repr(transparent)]
661661
pub struct NodeFlags : RawFlags {
662662
/// Default (empty)
@@ -696,7 +696,7 @@ impl NodeFlags {
696696
}
697697

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

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

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

tests/example_flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn clip_invalid_flags() {
1414
assert!(simplification_flags.is_valid());
1515

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

1919
// ... and use this function to check.
2020
assert!(!simplification_flags.is_valid());

0 commit comments

Comments
 (0)