GitXplorerGitXplorer
K

bitflags-serde-legacy

public
1 stars
1 forks
0 issues

Commits

List of commits on branch main.
Verified
2e4081516d4e7b4bfc3de674ad47dac689092a0c

Merge pull request #3 from RDruon/patch-1

KKodrAus committed a year ago
Verified
26b16c51bb4a6eb65d4a677bd0cf03dcb0ef51c3

Update README.md

RRDruon committed a year ago
Verified
9e44da22ee5b2435740878c965f71462ed65d39f

Merge pull request #2 from KodrAus/cargo/0.1.1

KKodrAus committed 2 years ago
Unverified
fec3102628838a1579b018288ded8dde62871db5

prepare for 0.1.1 release

KKodrAus committed 2 years ago
Verified
b2d8bcfcb6829278d8ab7292960bd457d4f32d8c

Merge pull request #1 from KodrAus/fix/bitflags-upgrade

KKodrAus committed 2 years ago
Unverified
b4cc5f1b3fcd7f6293968d933b95778b76abb39d

fix Flags trait

KKodrAus committed 2 years ago

README

The README file for this repository.

bitflags-serde-legacy

The serialization format used by bitflags! has changed between 1.x and 2.x. If you previously #[derive(Serialize, Deserialize], then you can use this library to maintain compatibility while upgrading.

Usage

You can either use this as a regular dependency, or pull the source into a private module in your project.

Add bitflags-serde-legacy to your Cargo.toml:

[dependencies.bitflags-serde-legacy]
version = "0.1.1"

Then, replace an existing #[derive(Serialize, Deserialize)] on your bitflags! generated types with the following manual implementations:

use bitflags::bitflags;

bitflags! {
    // #[derive(Serialize, Deserialize)]
    struct Flags: u32 {
        const A = 0b00000001;
        const B = 0b00000010;
        const C = 0b00000100;
        const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
    }
}

impl serde::Serialize for Flags {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        bitflags_serde_legacy::serialize(self, "Flags", serializer)
    }
}

impl<'de> serde::Deserialize<'de> for Flags {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        bitflags_serde_legacy::deserialize("Flags", deserializer)
    }
}