-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
use bitflags::bitflags; | ||
use option_set::option_set; | ||
|
||
option_set! { | ||
pub struct Test: UpperCamel + u8 { | ||
|
||
bitflags! { | ||
#[derive(serde::Serialize, serde::Deserialize)] | ||
pub struct TestGood: u8 { | ||
const One = 1; | ||
const Two = 1 << 1; | ||
const Three = 1 << 2; | ||
} | ||
} | ||
|
||
option_set! { | ||
pub struct TestBad: UpperCamel + u8 { | ||
const One = 1; | ||
const Two = 1 << 1; | ||
const Three = 1 << 2; | ||
} | ||
} | ||
|
||
|
||
fn main() { | ||
let flag = Test::One | Test::Two; | ||
let flag_good = TestGood::One | TestGood::Two; | ||
|
||
let json_ser_good = serde_json::ser::to_string(&flag_good).unwrap(); | ||
let ron_ser_good = ron::ser::to_string(&flag_good).unwrap(); | ||
|
||
let json_der_good: TestGood = serde_json::de::from_str(json_ser_good.as_str()).unwrap(); | ||
let ron_ser_good: TestGood = ron::de::from_str(ron_ser_good.as_str()).unwrap(); | ||
|
||
|
||
let flag_bad = TestBad::One | TestBad::Two; | ||
|
||
let json_ser = serde_json::ser::to_string(&flag).unwrap(); | ||
let ron_ser = ron::ser::to_string(&flag).unwrap(); | ||
let json_ser_bad = serde_json::ser::to_string(&flag_bad).unwrap(); | ||
let ron_ser_bad = ron::ser::to_string(&flag_bad).unwrap(); | ||
|
||
let json_der: Test = serde_json::de::from_str(json_ser.as_str()).unwrap(); | ||
let ron_ser: Test = ron::de::from_str(ron_ser.as_str()).unwrap(); | ||
let json_der_bad: TestBad = serde_json::de::from_str(json_ser_bad.as_str()).unwrap(); | ||
let ron_ser_bad: TestBad = ron::de::from_str(ron_ser_bad.as_str()).unwrap(); | ||
} |