| 1 | use serderust-analyzer cargo serde 1.0.228 crate/::{Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#}; |
| 2 | |
| 3 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.228 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Serializerust-analyzer cargo serde_derive 1.0.228 Serialize:)] |
| 4 | #[serde(rename_all = "kebab-case")] |
| 5 | enum MyEnumWithDashesrust-analyzer cargo ron 0.12.0 MyEnumWithDashes# { |
| 6 | ThisIsMyUnitVariantrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#ThisIsMyUnitVariant#, |
| 7 | ThisIsMyTupleVariantrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#ThisIsMyTupleVariant#(bool, i32), |
| 8 | } |
| 9 | |
| 10 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.228 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Serializerust-analyzer cargo serde_derive 1.0.228 Serialize:)] |
| 11 | #[serde(rename_all = "kebab-case")] |
| 12 | struct MyStructWithDashesrust-analyzer cargo ron 0.12.0 MyStructWithDashes# { |
| 13 | my_enumrust-analyzer cargo ron 0.12.0 MyStructWithDashes#my_enum.: MyEnumWithDashesrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#, |
| 14 | #[serderust-analyzer cargo serde_derive 1.0.228 serde:(rename = "2nd")] |
| 15 | my_enum2rust-analyzer cargo ron 0.12.0 MyStructWithDashes#my_enum2.: MyEnumWithDashesrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#, |
| 16 | will_be_renamedrust-analyzer cargo ron 0.12.0 MyStructWithDashes#will_be_renamed.: u32, |
| 17 | } |
| 18 | |
| 19 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 20 | fn roundtrip_ident_with_dashrust-analyzer cargo ron 0.12.0 roundtrip_ident_with_dash().() { |
| 21 | let value = MyStructWithDashesrust-analyzer cargo ron 0.12.0 MyStructWithDashes# { |
| 22 | my_enumrust-analyzer cargo ron 0.12.0 MyStructWithDashes#my_enum.: MyEnumWithDashesrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#::ThisIsMyUnitVariantrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#ThisIsMyUnitVariant#, |
| 23 | my_enum2rust-analyzer cargo ron 0.12.0 MyStructWithDashes#my_enum2.: MyEnumWithDashesrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#::ThisIsMyTupleVariantrust-analyzer cargo ron 0.12.0 MyEnumWithDashes#ThisIsMyTupleVariant#(false, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().3), |
| 24 | will_be_renamedrust-analyzer cargo ron 0.12.0 MyStructWithDashes#will_be_renamed.: 32, |
| 25 | }; |
| 26 | |
| 27 | let serial = ronrust-analyzer cargo ron 0.12.0 crate/::serrust-analyzer cargo ron 0.12.0 ser/::to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 28 | |
| 29 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Serialized: {}", serial); |
| 30 | |
| 31 | let deserial = ronrust-analyzer cargo ron 0.12.0 crate/::derust-analyzer cargo ron 0.12.0 de/::from_strrust-analyzer cargo ron 0.12.0 de/from_str().(&serial); |
| 32 | |
| 33 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value), deserial); |
| 34 | } |