Debian Codegraph @

tests/enum.rs

raw symbols SCIP
1 use serderust-analyzer cargo serde 1.0.144 crate/::Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#;
2 use serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::serrust-analyzer cargo serde_cbor_2 0.13.0 ser/::{Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#, SliceWriterust-analyzer cargo serde_cbor_2 0.13.0 write/SliceWrite#};
3
4 #[macro_use]
5 extern crate serderust-analyzer cargo serde_cbor_2 0.13.0 serde/;
6
7 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
8 fn test_simple_data_enum_roundtriprust-analyzer cargo serde_cbor_2 0.13.0 test_simple_data_enum_roundtrip().() {
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:, Serializerust-analyzer cargo serde_derive 1.0.144 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.144 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
10 enum DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 DataEnum# {
11 Arust-analyzer cargo serde_cbor_2 0.13.0 DataEnum#A#(u32),
12 Brust-analyzer cargo serde_cbor_2 0.13.0 DataEnum#B#(f32),
13 }
14
15 let a = DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 DataEnum#::Arust-analyzer cargo serde_cbor_2 0.13.0 DataEnum#A#(42);
16
17 let mut slice = [0u8; 64];
18 let writer = SliceWriterust-analyzer cargo serde_cbor_2 0.13.0 write/SliceWrite#::newrust-analyzer cargo serde_cbor_2 0.13.0 write/impl#[`SliceWrite<'a>`]new().(&mut slice);
19 let mut serializer = Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(writer);
20 a.serializerust-analyzer cargo serde_cbor_2 0.13.0 impl#[DataEnum][Serialize]serialize().(&mut serializer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
21 let writer = serializer.into_innerrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]into_inner().();
22 let end = writer.bytes_writtenrust-analyzer cargo serde_cbor_2 0.13.0 write/impl#[`SliceWrite<'a>`]bytes_written().();
23 let slice = writer.into_innerrust-analyzer cargo serde_cbor_2 0.13.0 write/impl#[`SliceWrite<'a>`]into_inner().();
24 let deserialized: DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 DataEnum# =
25 serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::derust-analyzer cargo serde_cbor_2 0.13.0 de/::from_slice_with_scratchrust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice_with_scratch().(&slice[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &mut []).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
26 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(a, deserialized);
27 }
28
29 #[cfg(feature = "std")]
30 mod std_testsrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ {
31 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#;
32
33 use serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::serrust-analyzer cargo serde_cbor_2 0.13.0 ser/::{IoWriterust-analyzer cargo serde_cbor_2 0.13.0 write/IoWrite#, Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#};
34 use serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::valuerust-analyzer cargo serde_cbor_2 0.13.0 value/::Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#;
35 use serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::{from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice()., to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().};
36
37 pub fn to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().<T>(value: &T) -> serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::Resultrust-analyzer cargo serde_cbor_2 0.13.0 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>
38 where
39 T: serderust-analyzer cargo serde 1.0.144 crate/::serrust-analyzer cargo serde 1.0.144 ser/::Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#,
40 {
41 let mut vec = 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().();
42 value.serializerust-analyzer cargo serde 1.0.144 ser/Serialize#serialize().(&mut Serializerrust-analyzer cargo serde_cbor_2 0.13.0 ser/Serializer#::newrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]new().(&mut IoWriterust-analyzer cargo serde_cbor_2 0.13.0 write/IoWrite#::newrust-analyzer cargo serde_cbor_2 0.13.0 write/impl#[`IoWrite<W>`]new().(&mut vec)).legacy_enumsrust-analyzer cargo serde_cbor_2 0.13.0 ser/impl#[`Serializer<W>`]legacy_enums().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
43 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(vec)
44 }
45
46 #[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.144 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.144 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:)]
47 enum Enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum# {
48 Arust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#A#,
49 Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#B#,
50 }
51
52 #[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.144 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.144 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:)]
53 struct EnumStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/EnumStruct# {
54 erust-analyzer cargo serde_cbor_2 0.13.0 std_tests/EnumStruct#e.: Enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#,
55 }
56
57 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
58 fn test_enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_enum().() {
59 let enum_struct = EnumStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/EnumStruct# { erust-analyzer cargo serde_cbor_2 0.13.0 std_tests/EnumStruct#e.: Enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#::Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#B# };
60 let raw = &to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&enum_struct).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
61 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("raw enum {raw:?}");
62 let re: EnumStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/EnumStruct# = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(raw).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
63 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(enum_struct, re);
64 }
65
66 #[repr(u16)]
67 #[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.144 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.144 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:)]
68 enum ReprEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnum# {
69 Arust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnum#A#,
70 Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnum#B#,
71 }
72
73 #[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.144 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.144 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:)]
74 struct ReprEnumStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnumStruct# {
75 erust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnumStruct#e.: ReprEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnum#,
76 }
77
78 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
79 fn test_repr_enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_repr_enum().() {
80 let repr_enum_struct = ReprEnumStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnumStruct# { erust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnumStruct#e.: ReprEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnum#::Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnum#B# };
81 let re: ReprEnumStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ReprEnumStruct# = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&repr_enum_struct).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
82 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repr_enum_struct, re);
83 }
84
85 #[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.144 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.144 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:)]
86 enum DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum# {
87 Arust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#A#(u32),
88 Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#B#(bool, u8),
89 Crust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#C# { xrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#C#x.: u8, yrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#C#y.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
90 }
91
92 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
93 fn test_data_enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_data_enum().() {
94 let data_enum_a = DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#::Arust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#A#(4);
95 let re_a: DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum# = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&data_enum_a).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
96 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data_enum_a, re_a);
97 let data_enum_b = DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#::Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#B#(true, 42);
98 let re_b: DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum# = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&data_enum_b).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
99 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data_enum_b, re_b);
100 let data_enum_c = DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#::Crust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#C# {
101 xrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#C#x.: 3,
102 yrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#C#y.: "foo".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
103 };
104 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", &to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&data_enum_c).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
105 let re_c: DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum# = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&data_enum_c).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
106 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data_enum_c, re_c);
107 }
108
109 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
110 fn test_serializerust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_serialize().() {
111 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&Enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#::Arust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#A#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), &[97, 65]);
112 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&Enumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#::Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Enum#B#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), &[97, 66]);
113 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
114 to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#::Arust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#A#(42)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
115 &[130, 97, 65, 24, 42]
116 );
117 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
118 to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&DataEnumrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#::Brust-analyzer cargo serde_cbor_2 0.13.0 std_tests/DataEnum#B#(true, 9)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
119 &[131, 97, 66, 245, 9]
120 );
121 }
122
123 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
124 fn test_newtype_structrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_newtype_struct().() {
125 #[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.144 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.144 Serialize:, 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:)]
126 pub struct Newtyperust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Newtype#(u8);
127 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&142u8).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&Newtyperust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Newtype#(142u8)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
128 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().::<Newtyperust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Newtype#>(&[24, 142]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), Newtyperust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Newtype#(142));
129 }
130
131 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.144 Deserialize:, 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/macros/Debug:)]
132 enum Foorust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Foo# {
133 #[serderust-analyzer cargo serde_derive 1.0.144 serde:(rename = "require")]
134 Requirerust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Foo#Require#,
135 }
136
137 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
138 fn test_variable_length_arrayrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_variable_length_array().() {
139 let slice = b"\x9F\x67\x72\x65\x71\x75\x69\x72\x65\xFF";
140 let value: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Foorust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Foo#> = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(slice).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
141 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, [Foorust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Foo#::Requirerust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Foo#Require#]);
142 }
143
144 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.144 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.144 Deserialize:, 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/macros/Debug:)]
145 enum Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar# {
146 Emptyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Empty#,
147 Numberrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Number#(i32),
148 Flagrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Flag#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, bool),
149 Pointrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point# { xrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#x.: i32, yrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#y.: i32 },
150 }
151
152 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
153 fn test_enum_as_maprust-analyzer cargo serde_cbor_2 0.13.0 std_tests/test_enum_as_map().() {
154 // unit variants serialize like bare strings
155 let empty_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Emptyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Empty#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
156 let empty_str_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&"Empty").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
157 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(empty_s, empty_str_s);
158
159 // tuple-variants serialize like ["<variant>", values..]
160 let number_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Numberrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Number#(42)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
161 let number_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#("Number".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Integerrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Integer#(42)];
162 let number_vec_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&number_vec).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
163 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(number_s, number_vec_s);
164
165 let flag_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Flagrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Flag#("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), true)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
166 let flag_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
167 Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#("Flag".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
168 Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
169 Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Boolrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Bool#(true),
170 ];
171 let flag_vec_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&flag_vec).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
172 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(flag_s, flag_vec_s);
173
174 // struct-variants serialize like ["<variant>", {struct..}]
175 let point_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Pointrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point# { xrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#x.: 5, yrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#y.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5 }).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
176 let mut struct_map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
177 struct_map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#("x".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Integerrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Integer#(5));
178 struct_map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#("y".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Integerrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Integer#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i128][Neg]neg().5));
179 let point_vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
180 Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#("Point".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
181 Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Maprust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Map#(struct_map.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][Clone]clone().()),
182 ];
183 let point_vec_s = to_vec_legacyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/to_vec_legacy().(&point_vec).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
184 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(point_s, point_vec_s);
185
186 // enum_as_map matches serde_json's default serialization for enums.
187
188 // unit variants still serialize like bare strings
189 let empty_s = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Emptyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Empty#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
190 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(empty_s, empty_str_s);
191
192 // 1-element tuple variants serialize like {"<variant>": value}
193 let number_s = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Numberrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Number#(42)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
194 let mut number_map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
195 number_map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("Number", 42);
196 let number_map_s = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&number_map).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
197 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(number_s, number_map_s);
198
199 // multi-element tuple variants serialize like {"<variant>": [values..]}
200 let flag_s = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Flagrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Flag#("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), true)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
201 let mut flag_map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
202 flag_map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(
203 "Flag",
204 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Textrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Text#("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Boolrust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Bool#(true)],
205 );
206 let flag_map_s = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&flag_map).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
207 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(flag_s, flag_map_s);
208
209 // struct-variants serialize like {"<variant>", {struct..}}
210 let point_s = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Pointrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point# { xrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#x.: 5, yrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#y.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5 }).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
211 let mut point_map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
212 point_map.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().("Point", Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Maprust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Map#(struct_map));
213 let point_map_s = to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&point_map).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
214 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(point_s, point_map_s);
215
216 // deserialization of all encodings should just work
217 let empty_str_ds = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&empty_str_s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
218 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Emptyrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Empty#, empty_str_ds);
219
220 let number_vec_ds = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&number_vec_s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
221 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Numberrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Number#(42), number_vec_ds);
222 let number_map_ds = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&number_map_s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
223 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Numberrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Number#(42), number_map_ds);
224
225 let flag_vec_ds = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&flag_vec_s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
226 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Flagrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Flag#("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), true), flag_vec_ds);
227 let flag_map_ds = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&flag_map_s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
228 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Flagrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Flag#("foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), true), flag_map_ds);
229
230 let point_vec_ds = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&point_vec_s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
231 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Pointrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point# { xrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#x.: 5, yrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#y.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5 }, point_vec_ds);
232 let point_map_ds = from_slicerust-analyzer cargo serde_cbor_2 0.13.0 de/from_slice().(&point_map_s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
233 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Barrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#::Pointrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point# { xrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#x.: 5, yrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Bar#Point#y.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5 }, point_map_ds);
234 }
235 }