| 1 | //! Serde Serialization and Deserialization |
| 2 | //! ======================================= |
| 3 | //! |
| 4 | //! Values can be serialized to bencode with `bendy::serde::to_bytes`, and |
| 5 | //! deserialized from bencode with `bendy::serde::from_bytes`: |
| 6 | //! |
| 7 | //! ``` |
| 8 | //! use bendy::serde::{from_bytes, to_bytes}; |
| 9 | //! use serde_ as serde; |
| 10 | //! use serde_derive::{Deserialize, Serialize}; |
| 11 | //! |
| 12 | //! assert_eq!(to_bytes(&10).unwrap(), b"i10e"); |
| 13 | //! assert_eq!(from_bytes::<u64>(b"i10e").unwrap(), 10); |
| 14 | //! |
| 15 | //! #[serde(crate = "serde_")] |
| 16 | //! #[derive(Serialize, Deserialize, Debug, PartialEq)] |
| 17 | //! struct Foo { |
| 18 | //! bar: bool, |
| 19 | //! } |
| 20 | //! |
| 21 | //! assert_eq!(to_bytes(&Foo { bar: true }).unwrap(), b"d3:bari1ee"); |
| 22 | //! assert_eq!(from_bytes::<Foo>(b"d3:bari1ee").unwrap(), Foo { bar: true }); |
| 23 | //! ``` |
| 24 | //! |
| 25 | //! Bencode Representations |
| 26 | //! ----------------------- |
| 27 | //! |
| 28 | //! Rust types and values are represented in bencode as follows: |
| 29 | //! |
| 30 | //! - `true`: The integer value `1`. |
| 31 | //! - `false`: The integer value `0`. |
| 32 | //! - `char`: A string containing the UTF-8 encoding of the value. |
| 33 | //! - `f32`: Represented as a length-four bencode byte string containing the big- |
| 34 | //! endian order bytes of the IEEE-754 representation of the value. |
| 35 | //! - `f64`: Represented as a length-eight bencode byte string containing the big- |
| 36 | //! endian order bytes of the IEEE-754 representation of the value. |
| 37 | //! - `()`: Represented as the empty bencode list, `le`. |
| 38 | //! - `Some(t)`: Represented as a list containing the bencoding of `t`. |
| 39 | //! - `None`: Represented as the empty list. |
| 40 | //! - maps, including BTreeMap and HashMap: bencoded dictionaries. |
| 41 | //! - record structs: Represented as bencoded dictionaries with the fields of the |
| 42 | //! struct represented as UTF-8 keys mapped to the bencoded serializations of the |
| 43 | //! values. |
| 44 | //! - tuple structs: Represented as bencoded lists containing the serialized values |
| 45 | //! of the fields. |
| 46 | //! - unit structs: Represented as the empty bencode list, `le`. |
| 47 | //! - enum unit variants: Represented as a string containing the name of the variant, |
| 48 | //! - enum newtype variants: Represented as a dict mapping the name of the variant |
| 49 | //! to the value the variant contains. |
| 50 | //! - enum tuple variants: Represented as a dict mapping the name of the variant |
| 51 | //! to a list containing the fields of the enum. |
| 52 | //! - enum struct variants: Represented as a dict mapping the name of the variant |
| 53 | //! to the struct representation of the fields of the variant. |
| 54 | //! - untagged enums: Repesented as the variant value without any surrounding dictionary. |
| 55 | //! |
| 56 | //! Bencode dictionary keys may only be byte strings. For this reason, map types with |
| 57 | //! keys that do not serialize as byte strings are unsupported. |
| 58 | //! |
| 59 | //! Note that values of type `f32` and `f64` do not conform to bencode's canonical |
| 60 | //! representation rules. For example, both `f32` and `f64` support negative zero |
| 61 | //! values which have different bit patterns, but which represent the same logical |
| 62 | //! value as positive zero. |
| 63 | //! |
| 64 | //! If you require bencoded values to have canonical representations, then it is best |
| 65 | //! to avoid floating point values. |
| 66 | //! |
| 67 | //! Example Representations |
| 68 | //! ----------------------- |
| 69 | //! |
| 70 | //! ``` |
| 71 | //! use bendy::serde::to_bytes; |
| 72 | //! use serde::Serialize; |
| 73 | //! use serde_ as serde; |
| 74 | //! use serde_derive::Serialize; |
| 75 | //! use std::collections::HashMap; |
| 76 | //! |
| 77 | //! fn repr(value: impl Serialize, bencode: impl AsRef<[u8]>) { |
| 78 | //! assert_eq!(to_bytes(&value).unwrap(), bencode.as_ref()); |
| 79 | //! } |
| 80 | //! |
| 81 | //! repr(true, "i1e"); |
| 82 | //! repr(false, "i0e"); |
| 83 | //! repr((), "le"); |
| 84 | //! repr('a', "1:a"); |
| 85 | //! repr('Å', b"2:\xC3\x85"); |
| 86 | //! repr(0, "i0e"); |
| 87 | //! repr(-15, "i-15e"); |
| 88 | //! repr(1.0f32, b"4:\x3F\x80\x00\x00"); |
| 89 | //! repr(1.0f64, b"8:\x3F\xF0\x00\x00\x00\x00\x00\x00"); |
| 90 | //! |
| 91 | //! let none: Option<i32> = None; |
| 92 | //! repr(none, "le"); |
| 93 | //! repr(Some(0), "li0ee"); |
| 94 | //! |
| 95 | //! let mut map = HashMap::new(); |
| 96 | //! map.insert("foo", 1); |
| 97 | //! map.insert("bar", 2); |
| 98 | //! repr(map, "d3:bari2e3:fooi1ee"); |
| 99 | //! |
| 100 | //! #[serde(crate = "serde_")] |
| 101 | //! #[derive(Serialize)] |
| 102 | //! struct Unit; |
| 103 | //! repr(Unit, "le"); |
| 104 | //! |
| 105 | //! #[serde(crate = "serde_")] |
| 106 | //! #[derive(Serialize)] |
| 107 | //! struct Newtype(String); |
| 108 | //! repr(Newtype("foo".into()), "3:foo"); |
| 109 | //! |
| 110 | //! #[serde(crate = "serde_")] |
| 111 | //! #[derive(Serialize)] |
| 112 | //! struct Tuple(bool, i32); |
| 113 | //! repr(Tuple(false, 100), "li0ei100ee"); |
| 114 | //! |
| 115 | //! #[serde(crate = "serde_")] |
| 116 | //! #[derive(Serialize)] |
| 117 | //! struct Record { |
| 118 | //! a: String, |
| 119 | //! b: bool, |
| 120 | //! } |
| 121 | //! |
| 122 | //! repr( |
| 123 | //! Record { |
| 124 | //! a: "hello".into(), |
| 125 | //! b: false, |
| 126 | //! }, |
| 127 | //! "d1:a5:hello1:bi0ee", |
| 128 | //! ); |
| 129 | //! |
| 130 | //! #[serde(crate = "serde_")] |
| 131 | //! #[derive(Serialize)] |
| 132 | //! enum Enum { |
| 133 | //! Unit, |
| 134 | //! Newtype(i32), |
| 135 | //! Tuple(bool, i32), |
| 136 | //! Struct { a: char, b: bool }, |
| 137 | //! } |
| 138 | //! |
| 139 | //! repr(Enum::Unit, "4:Unit"); |
| 140 | //! repr(Enum::Newtype(-1), "d7:Newtypei-1ee"); |
| 141 | //! repr(Enum::Tuple(true, 10), "d5:Tupleli1ei10eee"); |
| 142 | //! repr(Enum::Struct { a: 'x', b: true }, "d6:Structd1:a1:x1:bi1eee"); |
| 143 | //! |
| 144 | //! #[serde(untagged)] |
| 145 | //! #[serde(crate = "serde_")] |
| 146 | //! #[derive(Serialize)] |
| 147 | //! enum Untagged { |
| 148 | //! Foo { x: i32 }, |
| 149 | //! Bar { y: char }, |
| 150 | //! } |
| 151 | //! |
| 152 | //! repr(Untagged::Foo { x: -1 }, "d1:xi-1ee"); |
| 153 | //! repr(Untagged::Bar { y: 'z' }, "d1:y1:ze"); |
| 154 | //! ``` |
| 155 | |
| 156 | mod commonrust-analyzer cargo bendy 0.6.1 serde/common/; |
| 157 | |
| 158 | pub mod derust-analyzer cargo bendy 0.6.1 serde/de/; |
| 159 | pub mod errorrust-analyzer cargo bendy 0.6.1 serde/error/; |
| 160 | pub mod serrust-analyzer cargo bendy 0.6.1 serde/ser/; |
| 161 | |
| 162 | pub use derust-analyzer cargo bendy 0.6.1 serde/de/::{Deserializerrust-analyzer cargo bendy 0.6.1 serde/de/Deserializer#, from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().}; |
| 163 | pub use errorrust-analyzer cargo bendy 0.6.1 serde/error/::{Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#, Resultrust-analyzer cargo bendy 0.6.1 serde/error/Result#}; |
| 164 | pub use serrust-analyzer cargo bendy 0.6.1 serde/ser/::{Serializerrust-analyzer cargo bendy 0.6.1 serde/ser/Serializer#, to_bytesrust-analyzer cargo bendy 0.6.1 serde/ser/to_bytes().}; |
| 165 | |
| 166 | #[cfg(test)] |
| 167 | mod testsrust-analyzer cargo bendy 0.6.1 serde/tests/ { |
| 168 | use superrust-analyzer cargo bendy 0.6.1 serde/::commonrust-analyzer cargo bendy 0.6.1 serde/common/::*; |
| 169 | |
| 170 | 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/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#}; |
| 171 | |
| 172 | use superrust-analyzer cargo bendy 0.6.1 serde/::{ |
| 173 | derust-analyzer cargo bendy 0.6.1 serde/de/::{Deserializerrust-analyzer cargo bendy 0.6.1 serde/de/Deserializer#, from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().}, |
| 174 | serrust-analyzer cargo bendy 0.6.1 serde/ser/::to_bytesrust-analyzer cargo bendy 0.6.1 serde/ser/to_bytes()., |
| 175 | }; |
| 176 | |
| 177 | use serderust-analyzer cargo serde 1.0.140 crate/::{derust-analyzer cargo serde 1.0.140 de/::DeserializeOwnedrust-analyzer cargo serde 1.0.140 de/DeserializeOwned#, serrust-analyzer cargo serde 1.0.140 ser/::Serializerust-analyzer cargo serde 1.0.140 ser/Serialize#}; |
| 178 | use serde_deriverust-analyzer cargo serde_derive 1.0.140 crate/::{Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:}; |
| 179 | |
| 180 | fn caserust-analyzer cargo bendy 0.6.1 serde/tests/case().<V, B>(value: V, want: B) |
| 181 | where |
| 182 | V: Serializerust-analyzer cargo serde 1.0.140 ser/Serialize# + DeserializeOwnedrust-analyzer cargo serde 1.0.140 de/DeserializeOwned# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 183 | B: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>, |
| 184 | { |
| 185 | let want = want.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 186 | |
| 187 | let encoded = match to_bytesrust-analyzer cargo bendy 0.6.1 serde/ser/to_bytes().(&value) { |
| 188 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(have) => { |
| 189 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 190 | have, |
| 191 | want, |
| 192 | "Expected `{}` but got `{}` when serializing `{:?}`", |
| 193 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&want), |
| 194 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&have), |
| 195 | value |
| 196 | ); |
| 197 | have |
| 198 | }, |
| 199 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to serialize `{:?}`: {}", value, err), |
| 200 | }; |
| 201 | |
| 202 | let deserialized = match from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().::<V>(&encoded) { |
| 203 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(deserialized) => deserialized, |
| 204 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 205 | "Failed to deserialize `{:?}` from `{}`: {}", |
| 206 | value, |
| 207 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&encoded), |
| 208 | error |
| 209 | ), |
| 210 | }; |
| 211 | |
| 212 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 213 | deserialized, value, |
| 214 | "Deserialized value != original: `{:?}` != `{:?}`", |
| 215 | deserialized, value |
| 216 | ); |
| 217 | } |
| 218 | |
| 219 | fn case_borrowedrust-analyzer cargo bendy 0.6.1 serde/tests/case_borrowed().<V, B>(value: V, want: B) |
| 220 | where |
| 221 | V: Serializerust-analyzer cargo serde 1.0.140 ser/Serialize# + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 222 | B: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>, |
| 223 | { |
| 224 | let want = want.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 225 | |
| 226 | match to_bytesrust-analyzer cargo bendy 0.6.1 serde/ser/to_bytes().(&value) { |
| 227 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(have) => { |
| 228 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 229 | have, |
| 230 | want, |
| 231 | "Expected `{}` but got `{}` when serializing `{:?}`", |
| 232 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&want), |
| 233 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&have), |
| 234 | value |
| 235 | ); |
| 236 | }, |
| 237 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Failed to serialize `{:?}`: {}", value, err), |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 242 | fn scalarrust-analyzer cargo bendy 0.6.1 serde/tests/scalar().() { |
| 243 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(false, "i0e"); |
| 244 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(true, "i1e"); |
| 245 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0u8, "i0e"); |
| 246 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1u8, "i1e"); |
| 247 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0u16, "i0e"); |
| 248 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1u16, "i1e"); |
| 249 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0u32, "i0e"); |
| 250 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1u32, "i1e"); |
| 251 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0u64, "i0e"); |
| 252 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1u64, "i1e"); |
| 253 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0u128, "i0e"); |
| 254 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1u128, "i1e"); |
| 255 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0usize, "i0e"); |
| 256 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1usize, "i1e"); |
| 257 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0i8, "i0e"); |
| 258 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1i8, "i1e"); |
| 259 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][Neg]neg().1i8, "i-1e"); |
| 260 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0i16, "i0e"); |
| 261 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1i16, "i1e"); |
| 262 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1i16, "i-1e"); |
| 263 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0i32, "i0e"); |
| 264 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1i32, "i1e"); |
| 265 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1i32, "i-1e"); |
| 266 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0i64, "i0e"); |
| 267 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1i64, "i1e"); |
| 268 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1i64, "i-1e"); |
| 269 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0i128, "i0e"); |
| 270 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1i128, "i1e"); |
| 271 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i128][Neg]neg().1i128, "i-1e"); |
| 272 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(0isize, "i0e"); |
| 273 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(1isize, "i1e"); |
| 274 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1isize, "i-1e"); |
| 275 | } |
| 276 | |
| 277 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 278 | fn f32rust-analyzer cargo bendy 0.6.1 serde/tests/f32().() { |
| 279 | let value = 100.100f32; |
| 280 | let bytes = value.to_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]to_bits().().to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().(); |
| 281 | let mut bencode: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 282 | bencode.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(b"4:"); |
| 283 | bencode.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&bytes); |
| 284 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(value, bencode); |
| 285 | } |
| 286 | |
| 287 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 288 | fn f64rust-analyzer cargo bendy 0.6.1 serde/tests/f64().() { |
| 289 | let value = 100.100f64; |
| 290 | let bytes = value.to_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]to_bits().().to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]to_be_bytes().(); |
| 291 | let mut bencode: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 292 | bencode.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(b"8:"); |
| 293 | bencode.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&bytes); |
| 294 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(value, bencode); |
| 295 | } |
| 296 | |
| 297 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 298 | fn unitrust-analyzer cargo bendy 0.6.1 serde/tests/unit().() { |
| 299 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().((), "le"); |
| 300 | } |
| 301 | |
| 302 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 303 | fn nonerust-analyzer cargo bendy 0.6.1 serde/tests/none().() { |
| 304 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().::<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>, &str>(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, "le"); |
| 305 | } |
| 306 | |
| 307 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 308 | fn somerust-analyzer cargo bendy 0.6.1 serde/tests/some().() { |
| 309 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0), "li0ee"); |
| 310 | } |
| 311 | |
| 312 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 313 | fn charrust-analyzer cargo bendy 0.6.1 serde/tests/char().() { |
| 314 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().('a', "1:a"); |
| 315 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().('\u{1F9D0}', "4:\u{1F9D0}"); |
| 316 | } |
| 317 | |
| 318 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 319 | fn strrust-analyzer cargo bendy 0.6.1 serde/tests/str().() { |
| 320 | case_borrowedrust-analyzer cargo bendy 0.6.1 serde/tests/case_borrowed().("foo", "3:foo"); |
| 321 | } |
| 322 | |
| 323 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 324 | fn stringrust-analyzer cargo bendy 0.6.1 serde/tests/string().() { |
| 325 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "3:foo"); |
| 326 | } |
| 327 | |
| 328 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 329 | fn bytes_defaultrust-analyzer cargo bendy 0.6.1 serde/tests/bytes_default().() { |
| 330 | let value: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3, 4]; |
| 331 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(value, "li1ei2ei3ei4ee"); |
| 332 | } |
| 333 | |
| 334 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 335 | fn bytes_with_serde_bytesrust-analyzer cargo bendy 0.6.1 serde/tests/bytes_with_serde_bytes().() { |
| 336 | #[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:, Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 337 | #[serde(crate = "serde_")] |
| 338 | #[serde(transparent)] |
| 339 | struct Ownedrust-analyzer cargo bendy 0.6.1 serde/tests/Owned# { |
| 340 | #[serderust-analyzer cargo serde_derive 1.0.140 serde:(with = "serde_bytes")] |
| 341 | bytesrust-analyzer cargo bendy 0.6.1 serde/tests/Owned#bytes.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 342 | } |
| 343 | |
| 344 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().( |
| 345 | Ownedrust-analyzer cargo bendy 0.6.1 serde/tests/Owned# { |
| 346 | bytesrust-analyzer cargo bendy 0.6.1 serde/tests/Owned#bytes.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3], |
| 347 | }, |
| 348 | "3:\x01\x02\x03", |
| 349 | ); |
| 350 | |
| 351 | #[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:, Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 352 | #[serde(crate = "serde_")] |
| 353 | #[serde(transparent)] |
| 354 | struct Borrowedrust-analyzer cargo bendy 0.6.1 serde/tests/Borrowed#<'bytes> { |
| 355 | #[serderust-analyzer cargo serde_derive 1.0.140 serde:(with = "serde_bytes")] |
| 356 | bytesrust-analyzer cargo bendy 0.6.1 serde/tests/Borrowed#bytes.: &'bytes [u8], |
| 357 | } |
| 358 | |
| 359 | case_borrowedrust-analyzer cargo bendy 0.6.1 serde/tests/case_borrowed().(Borrowedrust-analyzer cargo bendy 0.6.1 serde/tests/Borrowed# { bytesrust-analyzer cargo bendy 0.6.1 serde/tests/Borrowed#bytes.: &[1, 2, 3] }, b"3:\x01\x02\x03"); |
| 360 | } |
| 361 | |
| 362 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 363 | fn maprust-analyzer cargo bendy 0.6.1 serde/tests/map().() { |
| 364 | let mut map = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(); |
| 365 | map.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("foo".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), 1); |
| 366 | map.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("bar".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), 2); |
| 367 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(map, "d3:bari2e3:fooi1ee"); |
| 368 | } |
| 369 | |
| 370 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 371 | fn map_non_byte_keyrust-analyzer cargo bendy 0.6.1 serde/tests/map_non_byte_key().() { |
| 372 | let mut map = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(); |
| 373 | map.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(1, 1); |
| 374 | map.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(2, 2); |
| 375 | assert_matchesrust-analyzer cargo bendy 0.6.1 assert_matches/assert_matches!!(to_bytesrust-analyzer cargo bendy 0.6.1 serde/ser/to_bytes().(&map), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::ArbitraryMapKeysUnsupportedrust-analyzer cargo bendy 0.6.1 serde/error/Error#ArbitraryMapKeysUnsupported#)); |
| 376 | } |
| 377 | |
| 378 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 379 | fn unit_structrust-analyzer cargo bendy 0.6.1 serde/tests/unit_struct().() { |
| 380 | #[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:, Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 381 | #[serde(crate = "serde_")] |
| 382 | struct Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo#; |
| 383 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo#, "le"); |
| 384 | } |
| 385 | |
| 386 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 387 | fn newtype_structrust-analyzer cargo bendy 0.6.1 serde/tests/newtype_struct().() { |
| 388 | #[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:, Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 389 | #[serde(crate = "serde_")] |
| 390 | struct Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo#(u8); |
| 391 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo#(1), "i1e"); |
| 392 | } |
| 393 | |
| 394 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 395 | fn seqrust-analyzer cargo bendy 0.6.1 serde/tests/seq().() { |
| 396 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 0, 1], "li1ei0ei1ee"); |
| 397 | } |
| 398 | |
| 399 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 400 | fn tuple_structrust-analyzer cargo bendy 0.6.1 serde/tests/tuple_struct().() { |
| 401 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 402 | #[serde(crate = "serde_")] |
| 403 | struct Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, u32, i32); |
| 404 | |
| 405 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo#("hello".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().100), "l5:helloi1ei-100ee"); |
| 406 | } |
| 407 | |
| 408 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 409 | fn record_structrust-analyzer cargo bendy 0.6.1 serde/tests/record_struct().() { |
| 410 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 411 | #[serde(crate = "serde_")] |
| 412 | struct Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo# { |
| 413 | arust-analyzer cargo bendy 0.6.1 serde/tests/Foo#a.: u8, |
| 414 | brust-analyzer cargo bendy 0.6.1 serde/tests/Foo#b.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 415 | } |
| 416 | |
| 417 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().( |
| 418 | Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo# { |
| 419 | arust-analyzer cargo bendy 0.6.1 serde/tests/Foo#a.: 1, |
| 420 | brust-analyzer cargo bendy 0.6.1 serde/tests/Foo#b.: "hello".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 421 | }, |
| 422 | "d1:ai1e1:b5:helloe", |
| 423 | ); |
| 424 | } |
| 425 | |
| 426 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 427 | fn struct_field_orderrust-analyzer cargo bendy 0.6.1 serde/tests/struct_field_order().() { |
| 428 | // Serde serializes the fields of this struct in the opposite |
| 429 | // order to that mandated by bencode. This would trigger an |
| 430 | // error if the struct serializer failed to correctly order |
| 431 | // the fields during serialization. |
| 432 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 433 | #[serde(crate = "serde_")] |
| 434 | struct Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo# { |
| 435 | facrust-analyzer cargo bendy 0.6.1 serde/tests/Foo#fac.: u8, |
| 436 | fbrust-analyzer cargo bendy 0.6.1 serde/tests/Foo#fb.: u8, |
| 437 | } |
| 438 | |
| 439 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo# { facrust-analyzer cargo bendy 0.6.1 serde/tests/Foo#fac.: 0, fbrust-analyzer cargo bendy 0.6.1 serde/tests/Foo#fb.: 1 }, "d3:faci0e2:fbi1ee"); |
| 440 | } |
| 441 | |
| 442 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 443 | fn enum_testsrust-analyzer cargo bendy 0.6.1 serde/tests/enum_tests().() { |
| 444 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 445 | #[serde(crate = "serde_")] |
| 446 | enum Enumrust-analyzer cargo bendy 0.6.1 serde/tests/Enum# { |
| 447 | Unitrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Unit#, |
| 448 | Newtyperust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Newtype#(i32), |
| 449 | Tuplerust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Tuple#(bool, i32), |
| 450 | Structrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Struct# { arust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Struct#a.: char, brust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Struct#b.: bool }, |
| 451 | } |
| 452 | |
| 453 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Enumrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#::Unitrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Unit#, "4:Unit"); |
| 454 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Enumrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#::Newtyperust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Newtype#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1), "d7:Newtypei-1ee"); |
| 455 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Enumrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#::Tuplerust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Tuple#(true, 10), "d5:Tupleli1ei10eee"); |
| 456 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Enumrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#::Structrust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Struct# { arust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Struct#a.: 'x', brust-analyzer cargo bendy 0.6.1 serde/tests/Enum#Struct#b.: true }, "d6:Structd1:a1:x1:bi1eee"); |
| 457 | } |
| 458 | |
| 459 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 460 | fn untagged_enumrust-analyzer cargo bendy 0.6.1 serde/tests/untagged_enum().() { |
| 461 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 462 | #[serde(untagged)] |
| 463 | #[serde(crate = "serde_")] |
| 464 | enum Untaggedrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged# { |
| 465 | Foorust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Foo# { xrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Foo#x.: i32 }, |
| 466 | Barrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Bar# { yrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Bar#y.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# }, |
| 467 | } |
| 468 | |
| 469 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Untaggedrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#::Foorust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Foo# { xrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Foo#x.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1 }, "d1:xi-1ee"); |
| 470 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Untaggedrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#::Barrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Bar# { yrust-analyzer cargo bendy 0.6.1 serde/tests/Untagged#Bar#y.: "z".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() }, "d1:y1:ze"); |
| 471 | } |
| 472 | |
| 473 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 474 | fn flattenrust-analyzer cargo bendy 0.6.1 serde/tests/flatten().() { |
| 475 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 476 | #[serde(crate = "serde_")] |
| 477 | struct Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo# { |
| 478 | #[serderust-analyzer cargo serde_derive 1.0.140 serde:(flatten)] |
| 479 | barrust-analyzer cargo bendy 0.6.1 serde/tests/Foo#bar.: Barrust-analyzer cargo bendy 0.6.1 serde/tests/Bar#, |
| 480 | } |
| 481 | |
| 482 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.140 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.140 Deserialize:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 483 | #[serde(crate = "serde_")] |
| 484 | struct Barrust-analyzer cargo bendy 0.6.1 serde/tests/Bar# { |
| 485 | xrust-analyzer cargo bendy 0.6.1 serde/tests/Bar#x.: i32, |
| 486 | } |
| 487 | |
| 488 | caserust-analyzer cargo bendy 0.6.1 serde/tests/case().(Foorust-analyzer cargo bendy 0.6.1 serde/tests/Foo# { barrust-analyzer cargo bendy 0.6.1 serde/tests/Foo#bar.: Barrust-analyzer cargo bendy 0.6.1 serde/tests/Bar# { xrust-analyzer cargo bendy 0.6.1 serde/tests/Bar#x.: 1 } }, "d1:xi1ee"); |
| 489 | } |
| 490 | |
| 491 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 492 | fn invalid_boolrust-analyzer cargo bendy 0.6.1 serde/tests/invalid_bool().() { |
| 493 | assert_matchesrust-analyzer cargo bendy 0.6.1 assert_matches/assert_matches!!( |
| 494 | from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().::<bool>(b"i100e"), |
| 495 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::InvalidBoolrust-analyzer cargo bendy 0.6.1 serde/error/Error#InvalidBool#(ref value)) if value == "100" |
| 496 | ); |
| 497 | } |
| 498 | |
| 499 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 500 | fn invalid_f32rust-analyzer cargo bendy 0.6.1 serde/tests/invalid_f32().() { |
| 501 | assert_matchesrust-analyzer cargo bendy 0.6.1 assert_matches/assert_matches!!(from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().::<f32>(b"8:10000000"), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::InvalidF32rust-analyzer cargo bendy 0.6.1 serde/error/Error#InvalidF32#(8))); |
| 502 | } |
| 503 | |
| 504 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 505 | fn invalid_f64rust-analyzer cargo bendy 0.6.1 serde/tests/invalid_f64().() { |
| 506 | assert_matchesrust-analyzer cargo bendy 0.6.1 assert_matches/assert_matches!!(from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().::<f64>(b"4:1000"), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::InvalidF64rust-analyzer cargo bendy 0.6.1 serde/error/Error#InvalidF64#(4))); |
| 507 | } |
| 508 | |
| 509 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 510 | fn invalid_charrust-analyzer cargo bendy 0.6.1 serde/tests/invalid_char().() { |
| 511 | assert_matchesrust-analyzer cargo bendy 0.6.1 assert_matches/assert_matches!!(from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/from_bytes().::<char>(b"2:00"), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::InvalidCharrust-analyzer cargo bendy 0.6.1 serde/error/Error#InvalidChar#(2))); |
| 512 | } |
| 513 | |
| 514 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 515 | fn trailing_bytes_forbidrust-analyzer cargo bendy 0.6.1 serde/tests/trailing_bytes_forbid().() { |
| 516 | assert_matchesrust-analyzer cargo bendy 0.6.1 assert_matches/assert_matches!!( |
| 517 | Deserializerrust-analyzer cargo bendy 0.6.1 serde/de/Deserializer#::from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/impl#[`Deserializer<'de>`]from_bytes().(b"i1ei1e") |
| 518 | .with_forbid_trailing_bytesrust-analyzer cargo bendy 0.6.1 serde/de/impl#[`Deserializer<'de>`]with_forbid_trailing_bytes().(true) |
| 519 | .deserializerust-analyzer cargo bendy 0.6.1 serde/de/impl#[`Deserializer<'de>`]deserialize().::<u32>(), |
| 520 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo bendy 0.6.1 serde/error/Error#::TrailingBytesrust-analyzer cargo bendy 0.6.1 serde/error/Error#TrailingBytes#) |
| 521 | ); |
| 522 | } |
| 523 | |
| 524 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 525 | fn trailing_bytes_allowrust-analyzer cargo bendy 0.6.1 serde/tests/trailing_bytes_allow().() { |
| 526 | assert_matchesrust-analyzer cargo bendy 0.6.1 assert_matches/assert_matches!!( |
| 527 | Deserializerrust-analyzer cargo bendy 0.6.1 serde/de/Deserializer#::from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/impl#[`Deserializer<'de>`]from_bytes().(b"i1ei1e").deserializerust-analyzer cargo bendy 0.6.1 serde/de/impl#[`Deserializer<'de>`]deserialize().::<u32>(), |
| 528 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(1) |
| 529 | ); |
| 530 | } |
| 531 | |
| 532 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 533 | fn borrowed_valuerust-analyzer cargo bendy 0.6.1 serde/tests/borrowed_value().() { |
| 534 | use craterust-analyzer cargo bendy 0.6.1 crate/::valuerust-analyzer cargo bendy 0.6.1 value/::Valuerust-analyzer cargo bendy 0.6.1 value/Value#; |
| 535 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#; |
| 536 | |
| 537 | #[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.140 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 538 | #[serde(crate = "serde_")] |
| 539 | struct Dictrust-analyzer cargo bendy 0.6.1 serde/tests/Dict#<'a> { |
| 540 | #[serderust-analyzer cargo serde_derive 1.0.140 serde:(borrow)] |
| 541 | vrust-analyzer cargo bendy 0.6.1 serde/tests/Dict#v.: Valuerust-analyzer cargo bendy 0.6.1 value/Value#<'a>, |
| 542 | } |
| 543 | |
| 544 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 545 | Deserializerrust-analyzer cargo bendy 0.6.1 serde/de/Deserializer#::from_bytesrust-analyzer cargo bendy 0.6.1 serde/de/impl#[`Deserializer<'de>`]from_bytes().(b"d1:v3:\x01\x02\x03e") |
| 546 | .deserializerust-analyzer cargo bendy 0.6.1 serde/de/impl#[`Deserializer<'de>`]deserialize().::<Dictrust-analyzer cargo bendy 0.6.1 serde/tests/Dict#<'_>>() |
| 547 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 548 | Dictrust-analyzer cargo bendy 0.6.1 serde/tests/Dict# { |
| 549 | vrust-analyzer cargo bendy 0.6.1 serde/tests/Dict#v.: Valuerust-analyzer cargo bendy 0.6.1 value/Value#::Bytesrust-analyzer cargo bendy 0.6.1 value/Value#Bytes#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1, 2, 3])) |
| 550 | }, |
| 551 | ); |
| 552 | } |
| 553 | } |