diff --git a/Cargo.lock b/Cargo.lock index 576f94d5..326be4ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,7 +86,7 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags 2.5.0", + "bitflags", "cexpr", "clang-sys", "itertools", @@ -103,12 +103,6 @@ dependencies = [ "which", ] -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.5.0" @@ -548,7 +542,7 @@ version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.5.0", + "bitflags", "errno", "libc", "linux-raw-sys", @@ -672,7 +666,7 @@ dependencies = [ "anyhow", "bincode", "bindgen", - "bitflags 1.3.2", + "bitflags", "cc", "clap", "delegate", diff --git a/Cargo.toml b/Cargo.toml index 6a176b58..20de16cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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} diff --git a/src/sys/flags.rs b/src/sys/flags.rs index cf55bb3d..92b40900 100644 --- a/src/sys/flags.rs +++ b/src/sys/flags.rs @@ -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 @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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; @@ -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 @@ -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 @@ -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) @@ -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 { @@ -736,19 +736,13 @@ impl_from_for_flag_types!(TableOutputOptions); impl From 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 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) } } diff --git a/tests/example_flags.rs b/tests/example_flags.rs index c37101ad..c973db40 100644 --- a/tests/example_flags.rs +++ b/tests/example_flags.rs @@ -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());