A macro to generate structures which behave like bitflags
Full Changelog: https://github.com/bitflags/bitflags/compare/2.1.0...2.2.0
Full Changelog: https://github.com/bitflags/bitflags/compare/2.0.2...2.1.0
Full Changelog: https://github.com/bitflags/bitflags/compare/2.0.1...2.0.2
Full Changelog: https://github.com/bitflags/bitflags/compare/2.0.0...2.0.1
This release includes some major changes over 1.x
. If you use bitflags!
types in your public API then upgrading this library may cause breakage in your downstream users.
You'll need to add the serde
Cargo feature in order to #[derive(Serialize, Deserialize)]
on your generated flags types:
bitflags! {
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub struct Flags: T {
..
}
}
where T
is the underlying bits type you're using, such as u32
.
The default serialization format with serde
has changed if you #[derive(Serialize, Deserialize)]
on your generated flags types. It will now use a formatted string for human-readable formats and the underlying bits type for compact formats.
To keep the old format, see the https://github.com/KodrAus/bitflags-serde-legacy library.
Generated flags types now derive fewer traits. If you need to maintain backwards compatibility, you can derive the following yourself:
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
The unsafe from_bits_unchecked
method is now a safe from_bits_retain
method.
You can add the following method to your generated types to keep them compatible:
#[deprecated = "use the safe `from_bits_retain` method instead"]
pub unsafe fn from_bits_unchecked(bits: T) -> Self {
Self::from_bits_retain(bits)
}
where T
is the underlying bits type you're using, such as u32
.
.bits
fieldYou can now use the .bits()
method instead of the old .bits
.
The representation of generated flags types has changed from a struct with the single field bits
to a newtype.
Ok
by @konsumlamm in https://github.com/bitflags/bitflags/pull/266
Debug
implementation by @konsumlamm in https://github.com/bitflags/bitflags/pull/268
Full Changelog: https://github.com/bitflags/bitflags/compare/1.3.2...2.0.0
Full Changelog: https://github.com/bitflags/bitflags/compare/2.0.0-rc.2...2.0.0-rc.3
⚠️ NOTE ⚠️ This release changes the default serialization you'll get if you #[derive(Serialize, Deserialize)]
on your generated flags types. It will now use a formatted string for human-readable formats and the underlying bits
type for compact formats.
Full Changelog: https://github.com/bitflags/bitflags/compare/2.0.0-rc.1...2.0.0-rc.2
Ok
by @konsumlamm in https://github.com/bitflags/bitflags/pull/266
Debug
implementation by @konsumlamm in https://github.com/bitflags/bitflags/pull/268
Full Changelog: https://github.com/bitflags/bitflags/compare/1.3.2...2.0.0-rc.1
non_snake_case
in generated flags types (#256)#[repr(transparent)]
(#252)