Skip to content

Commit

Permalink
Upgrade to bitflags 2.0 (#443)
Browse files Browse the repository at this point in the history
* Upgrade to bitflags 2.0

* Update the fuzzer Cargo.lock
  • Loading branch information
juntyr committed May 1, 2023
1 parent c0d7421 commit ec889b5
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 67 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Depend on `serde_derive` directly to potentially enable more compilation parallelism ([#441](https://github.com/ron-rs/ron/pull/441))
- Add `compact_maps` and `compact_structs` options to `PrettyConfig` to allow serialising maps and structs on a single line ([#448](https://github.com/ron-rs/ron/pull/448))
- Add minimal support for `#[serde(flatten)]` with roundtripping through RON maps ([#455](https://github.com/ron-rs/ron/pull/455))
- Breaking: Bump `bitflags` dependency to 2.0, changes `serde` impls of `Extensions` ([#443](https://github.com/ron-rs/ron/pull/443))

## [0.8.0] - 2022-08-17

Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ integer128 = []

[dependencies]
base64 = "0.21"
bitflags = "1.3"
bitflags = { version = "2.0", features = ["serde"] }
indexmap = { version = "1.9", features = ["serde-1"], optional = true }
# serde supports i128/u128 from 1.0.60 onwards
serde = "1.0.60"
Expand All @@ -35,5 +35,4 @@ serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11"
serde_json = "1.0"
bitflags-serial = { git = "https://github.com/kvark/bitflags-serial" }
option_set = "0.1"
63 changes: 32 additions & 31 deletions fuzz/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 src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use base64::Engine;
use serde::de::{self, DeserializeSeed, Deserializer as SerdeError, Visitor};
use serde::de::{self, DeserializeSeed, Deserializer as _, Visitor};

use self::{id::IdDeserializer, tag::TagDeserializer};
pub use crate::error::{Error, Position, SpannedError};
Expand Down
2 changes: 1 addition & 1 deletion src/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde_derive::{Deserialize, Serialize};

bitflags::bitflags! {
#[derive(Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Extensions: usize {
const UNWRAP_NEWTYPES = 0x1;
const IMPLICIT_SOME = 0x2;
Expand Down
6 changes: 3 additions & 3 deletions src/value/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'de: 'a, 'a> Deserialize<'de> for &'a RawValue {
}

fn visit_borrowed_str<E: de::Error>(self, ron: &'de str) -> Result<Self::Value, E> {
match Options::default().from_str::<serde::de::IgnoredAny>(ron) {
match Options::default().from_str::<de::IgnoredAny>(ron) {
Ok(_) => Ok(RawValue::from_borrowed_str(ron)),
Err(err) => Err(de::Error::custom(format!(
"invalid RON value at {}: {}",
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<'de> Deserialize<'de> for Box<RawValue> {
}

fn visit_str<E: de::Error>(self, ron: &str) -> Result<Self::Value, E> {
match Options::default().from_str::<serde::de::IgnoredAny>(ron) {
match Options::default().from_str::<de::IgnoredAny>(ron) {
Ok(_) => Ok(RawValue::from_boxed_str(ron.to_owned().into_boxed_str())),
Err(err) => Err(de::Error::custom(format!(
"invalid RON value at {}: {}",
Expand All @@ -169,7 +169,7 @@ impl<'de> Deserialize<'de> for Box<RawValue> {
}

fn visit_string<E: de::Error>(self, ron: String) -> Result<Self::Value, E> {
match Options::default().from_str::<serde::de::IgnoredAny>(&ron) {
match Options::default().from_str::<de::IgnoredAny>(&ron) {
Ok(_) => Ok(RawValue::from_boxed_str(ron.into_boxed_str())),
Err(err) => Err(de::Error::custom(format!(
"invalid RON value at {}: {}",
Expand Down
36 changes: 7 additions & 29 deletions tests/152_bitflags.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use bitflags::*;
use option_set::option_set;

#[macro_use]
extern crate bitflags_serial;

bitflags! {
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
serde::Serialize, serde::Deserialize,
)]
struct TestGood: u8 {
const ONE = 1;
const TWO = 1 << 1;
Expand All @@ -14,21 +14,14 @@ bitflags! {
}

option_set! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct TestBad: UpperCamel + u8 {
const ONE = 1;
const TWO = 1 << 1;
const THREE = 1 << 2;
}
}

bitflags_serial! {
struct TestBadTWO: u8 {
const ONE = 1;
const TWO = 1 << 1;
const THREE = 1 << 2;
}
}

#[test]
fn test_bitflags() {
// Test case provided by jaynus in
Expand All @@ -39,8 +32,8 @@ fn test_bitflags() {
let json_ser_good = serde_json::ser::to_string(&flag_good).unwrap();
let ron_ser_good = ron::ser::to_string(&flag_good).unwrap();

assert_eq!(json_ser_good, "{\"bits\":3}");
assert_eq!(ron_ser_good, "(bits:3)");
assert_eq!(json_ser_good, "\"ONE | TWO\"");
assert_eq!(ron_ser_good, "(\"ONE | TWO\")");

let json_de_good: TestGood = serde_json::de::from_str(json_ser_good.as_str()).unwrap();
let ron_de_good: TestGood = ron::de::from_str(ron_ser_good.as_str()).unwrap();
Expand All @@ -62,19 +55,4 @@ fn test_bitflags() {

assert_eq!(json_de_bad, flag_bad);
assert_eq!(ron_de_bad, flag_bad);

// bitflags_serial
let flag_bad_two = TestBadTWO::ONE | TestBadTWO::TWO;

let json_ser_bad_two = serde_json::ser::to_string(&flag_bad_two).unwrap();
let ron_ser_bad_two = ron::ser::to_string(&flag_bad_two).unwrap();

assert_eq!(json_ser_bad_two, "[\"ONE\",\"TWO\"]");
assert_eq!(ron_ser_bad_two, "[ONE,TWO]");

let json_de_bad_two: TestBadTWO = serde_json::de::from_str(json_ser_bad_two.as_str()).unwrap();
let ron_de_bad_two: TestBadTWO = ron::de::from_str(ron_ser_bad_two.as_str()).unwrap();

assert_eq!(json_de_bad_two, flag_bad_two);
assert_eq!(ron_de_bad_two, flag_bad_two);
}

0 comments on commit ec889b5

Please sign in to comment.