| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#; |
| 2 | |
| 3 | use ronrust-analyzer cargo ron 0.12.0 crate/::{ |
| 4 | derust-analyzer cargo ron 0.12.0 de/::from_strrust-analyzer cargo ron 0.12.0 de/from_str()., |
| 5 | serrust-analyzer cargo ron 0.12.0 ser/::{to_string_prettyrust-analyzer cargo ron 0.12.0 ser/to_string_pretty()., PrettyConfigrust-analyzer cargo ron 0.12.0 ser/PrettyConfig#}, |
| 6 | }; |
| 7 | 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#}; |
| 8 | |
| 9 | #[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:, Serializerust-analyzer cargo serde_derive 1.0.228 Serialize:)] |
| 10 | struct Configrust-analyzer cargo ron 0.12.0 Config# { |
| 11 | booleanrust-analyzer cargo ron 0.12.0 Config#boolean.: bool, |
| 12 | floatrust-analyzer cargo ron 0.12.0 Config#float.: f32, |
| 13 | maprust-analyzer cargo ron 0.12.0 Config#map.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<u8, char>, |
| 14 | nestedrust-analyzer cargo ron 0.12.0 Config#nested.: Nestedrust-analyzer cargo ron 0.12.0 Nested#, |
| 15 | tuplerust-analyzer cargo ron 0.12.0 Config#tuple.: (u32, u32), |
| 16 | } |
| 17 | |
| 18 | #[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:, Serializerust-analyzer cargo serde_derive 1.0.228 Serialize:)] |
| 19 | struct Nestedrust-analyzer cargo ron 0.12.0 Nested# { |
| 20 | arust-analyzer cargo ron 0.12.0 Nested#a.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 21 | brust-analyzer cargo ron 0.12.0 Nested#b.: char, |
| 22 | } |
| 23 | |
| 24 | fn read_originalrust-analyzer cargo ron 0.12.0 read_original().(source: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 25 | source.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("\r\n", "\n") |
| 26 | } |
| 27 | |
| 28 | fn make_roundtriprust-analyzer cargo ron 0.12.0 make_roundtrip().(source: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 29 | let config: Configrust-analyzer cargo ron 0.12.0 Config# = from_strrust-analyzer cargo ron 0.12.0 de/from_str().(source).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 30 | let pretty = PrettyConfigrust-analyzer cargo ron 0.12.0 ser/PrettyConfig#::newrust-analyzer cargo ron 0.12.0 ser/impl#[PrettyConfig]new().() |
| 31 | .depth_limitrust-analyzer cargo ron 0.12.0 ser/impl#[PrettyConfig]depth_limit().(3) |
| 32 | .separate_tuple_membersrust-analyzer cargo ron 0.12.0 ser/impl#[PrettyConfig]separate_tuple_members().(true) |
| 33 | .enumerate_arraysrust-analyzer cargo ron 0.12.0 ser/impl#[PrettyConfig]enumerate_arrays().(true) |
| 34 | .new_linerust-analyzer cargo ron 0.12.0 ser/impl#[PrettyConfig]new_line().("\n"); |
| 35 | to_string_prettyrust-analyzer cargo ron 0.12.0 ser/to_string_pretty().(&config, pretty).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Serialization failed") |
| 36 | } |
| 37 | |
| 38 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 39 | fn test_sequence_ex1rust-analyzer cargo ron 0.12.0 test_sequence_ex1().() { |
| 40 | let file = include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("preserve_sequence_ex1.ron"); |
| 41 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(read_originalrust-analyzer cargo ron 0.12.0 read_original().(file), make_roundtriprust-analyzer cargo ron 0.12.0 make_roundtrip().(file)); |
| 42 | } |
| 43 | |
| 44 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 45 | fn test_sequence_ex2rust-analyzer cargo ron 0.12.0 test_sequence_ex2().() { |
| 46 | let file = include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("preserve_sequence_ex2.ron"); |
| 47 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(read_originalrust-analyzer cargo ron 0.12.0 read_original().(file), make_roundtriprust-analyzer cargo ron 0.12.0 make_roundtrip().(file)); |
| 48 | } |