Debian Codegraph @

tests/value.rs

raw symbols SCIP
1 #[cfg(feature = "std")]
2 mod std_testsrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/ {
3 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#;
4
5 use serderust-analyzer cargo serde 1.0.144 crate/::{Deserializerust-analyzer cargo serde 1.0.144 de/Deserialize#, Serializerust-analyzer cargo serde 1.0.144 ser/Serialize#};
6
7 #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, 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:)]
8 struct TupleStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/TupleStruct#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, i32, u64);
9
10 #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, 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:)]
11 struct UnitStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/UnitStruct#;
12
13 #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, 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:)]
14 struct Structrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#<'a> {
15 tuple_structrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#tuple_struct.: TupleStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/TupleStruct#,
16 tuplerust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#tuple.: (Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, f32, f64),
17 maprust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#map.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
18 bytesrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#bytes.: &'a [u8],
19 arrayrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#array.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
20 unit_arrayrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#unit_array.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<UnitStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/UnitStruct#>,
21 }
22
23 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#;
24 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#;
25
26 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
27 fn serderust-analyzer cargo serde_cbor_2 0.13.0 std_tests/serde().() {
28 let tuple_struct = TupleStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/TupleStruct#("test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().60, 3000);
29
30 let tuple = ("hello".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().50.004_097, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().12.094635556478);
31
32 let map = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::from_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`][`FromIterator<(K, V)>`]from_iter().(
33 [
34 ("key1".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "value1".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
35 ("key2".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "value2".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
36 ("key3".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "value3".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
37 ("key4".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "value4".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()),
38 ]
39 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
40 .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().(),
41 );
42
43 let bytes = b"test byte string";
44
45 let array = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("one"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("two"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("three")];
46 let unit_array = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![UnitStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/UnitStruct#, UnitStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/UnitStruct#, UnitStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/UnitStruct#];
47
48 let data = Structrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct# {
49 tuple_structrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#tuple_struct.,
50 tuplerust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#tuple.,
51 maprust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#map.,
52 bytesrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#bytes.,
53 arrayrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#array.,
54 unit_arrayrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/Struct#unit_array.,
55 };
56
57 let value = serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::valuerust-analyzer cargo serde_cbor_2 0.13.0 value/::to_valuerust-analyzer cargo serde_cbor_2 0.13.0 value/ser/to_value().(data.clonerust-analyzer cargo serde_cbor_2 0.13.0 std_tests/impl#[`Struct<'a>`][Clone]clone().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
58 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{value:?}");
59
60 let data_ser = serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::to_vecrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec().(&value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
61 let data_de_value: Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value# = 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().(&data_ser).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
62
63 fn as_objectrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/as_object().(value: &Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#) -> &BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#, Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#> {
64 if let Valuerust-analyzer cargo serde_cbor_2 0.13.0 value/Value#::Maprust-analyzer cargo serde_cbor_2 0.13.0 value/Value#Map#(ref v) = value {
65 return v;
66 }
67 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!()
68 }
69
70 for ((k1, v1), (k2, v2)) in as_objectrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/as_object().(&value)
71 .iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]iter().()
72 .ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(as_objectrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/as_object().(&data_de_value).iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]iter().())
73 {
74 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(k1, k2);
75 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(v1, v2);
76 }
77
78 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, data_de_value);
79 }
80
81 #[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:)]
82 struct SmallStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/SmallStruct# {
83 spamrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/SmallStruct#spam.: u32,
84 eggsrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/SmallStruct#eggs.: u32,
85 }
86
87 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
88 fn small_structrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/small_struct().() {
89 // Test whether the packed format works.
90 // Field names should not be serialized,
91 // instead field indizes are serialized.
92 let value = SmallStructrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/SmallStruct# { spamrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/SmallStruct#spam.: 17, eggsrust-analyzer cargo serde_cbor_2 0.13.0 std_tests/SmallStruct#eggs.: 42 };
93 let data = serde_cbor_2rust-analyzer cargo serde_cbor_2 0.13.0 crate/::serrust-analyzer cargo serde_cbor_2 0.13.0 ser/::to_vec_packedrust-analyzer cargo serde_cbor_2 0.13.0 ser/to_vec_packed().(&value).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
94 let reference = b"\xa2\x00\x11\x01\x18\x2a";
95 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data, reference);
96 }
97 }