Debian Codegraph @

tests/integration/from_value.rs

raw symbols SCIP
1 use craterust-analyzer cargo schemars 1.2.2 crate/::preluderust-analyzer cargo schemars 1.2.2 prelude/::*;
2 use schemarsrust-analyzer cargo schemars 1.2.2 crate/::generaterust-analyzer cargo schemars 1.2.2 generate/::SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#;
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 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
6 #[serde(rename_all = "camelCase")]
7 pub struct MyStructrust-analyzer cargo schemars 1.2.2 from_value/MyStruct# {
8 pub my_intrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_int.: i32,
9 pub my_boolrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_bool.: bool,
10 pub my_nullable_enumrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_nullable_enum.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MyEnumrust-analyzer cargo schemars 1.2.2 from_value/MyEnum#>,
11 pub my_inner_structrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_inner_struct.: MyInnerStructrust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#,
12 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(skip)]
13 pub _skiprust-analyzer cargo schemars 1.2.2 from_value/MyStruct#_skip.: i32,
14 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(skip_serializing_if = "Option::is_none")]
15 pub skip_if_nonerust-analyzer cargo schemars 1.2.2 from_value/MyStruct#skip_if_none.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MyEnumrust-analyzer cargo schemars 1.2.2 from_value/MyEnum#>,
16 }
17
18 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
19 pub struct MyInnerStructrust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct# {
20 pub my_maprust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_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#, f64>,
21 pub my_vecrust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_vec.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<f32>,
22 pub my_empty_maprust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_empty_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#, f64>,
23 pub my_empty_vecrust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_empty_vec.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<f32>,
24 pub my_tuplerust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_tuple.: (char, u8),
25 }
26
27 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
28 pub enum MyEnumrust-analyzer cargo schemars 1.2.2 from_value/MyEnum# {
29 NewTyperust-analyzer cargo schemars 1.2.2 from_value/MyEnum#NewType#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
30 Structrust-analyzer cargo schemars 1.2.2 from_value/MyEnum#Struct# { floatsrust-analyzer cargo schemars 1.2.2 from_value/MyEnum#Struct#floats.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<f32> },
31 }
32
33 fn struct_valuerust-analyzer cargo schemars 1.2.2 from_value/struct_value().() -> MyStructrust-analyzer cargo schemars 1.2.2 from_value/MyStruct# {
34 MyStructrust-analyzer cargo schemars 1.2.2 from_value/MyStruct# {
35 my_intrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_int.: 123,
36 my_boolrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_bool.: true,
37 my_nullable_enumrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_nullable_enum.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
38 my_inner_structrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#my_inner_struct.: MyInnerStructrust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct# {
39 my_maprust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_map.: [("k".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), 1.23)].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
40 my_vecrust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_vec.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![1.0, 2.0, 3.0],
41 my_empty_maprust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_empty_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().(),
42 my_empty_vecrust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_empty_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().(),
43 my_tuplerust-analyzer cargo schemars 1.2.2 from_value/MyInnerStruct#my_tuple.: ('💩', 42),
44 },
45 _skiprust-analyzer cargo schemars 1.2.2 from_value/MyStruct#_skip.: 123,
46 skip_if_nonerust-analyzer cargo schemars 1.2.2 from_value/MyStruct#skip_if_none.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
47 }
48 }
49
50 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
51 fn custom_structrust-analyzer cargo schemars 1.2.2 from_value/custom_struct().() {
52 let value = struct_valuerust-analyzer cargo schemars 1.2.2 from_value/struct_value().();
53
54 testrust-analyzer cargo schemars 1.2.2 test!!(value: value.clonerust-analyzer cargo schemars 1.2.2 from_value/impl#[MyStruct][Clone]clone().())
55 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
56 .assert_allows_ser_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip().([value, MyStructrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#::defaultrust-analyzer cargo schemars 1.2.2 from_value/impl#[MyStruct][Default]default().()]);
57 }
58
59 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
60 fn custom_struct_openapi3rust-analyzer cargo schemars 1.2.2 from_value/custom_struct_openapi3().() {
61 let value = struct_valuerust-analyzer cargo schemars 1.2.2 from_value/struct_value().();
62
63 testrust-analyzer cargo schemars 1.2.2 test!!(value: value.clonerust-analyzer cargo schemars 1.2.2 from_value/impl#[MyStruct][Clone]clone().(), SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::openapi3rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]openapi3().()).assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().();
64
65 // schemars uses a nonstandard meta-schema for openapi 3.0 which the jsonschema crate doesn't
66 // accept, so we swap it out for the standard draft-04 meta-schema.
67 let draft04 = "http://json-schema.org/draft-04/schema";
68 testrust-analyzer cargo schemars 1.2.2 test!!(value: value.clonerust-analyzer cargo schemars 1.2.2 from_value/impl#[MyStruct][Clone]clone().(), SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::openapi3rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]openapi3().().withrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]with().(|o| o.meta_schemarust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#meta_schema. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(draft04.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())))
69 .assert_allows_ser_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip().([value, MyStructrust-analyzer cargo schemars 1.2.2 from_value/MyStruct#::defaultrust-analyzer cargo schemars 1.2.2 from_value/impl#[MyStruct][Default]default().()]);
70 }
71
72 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
73 fn json_valuerust-analyzer cargo schemars 1.2.2 from_value/json_value().() {
74 let value = jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!({
75 "zero": 0,
76 "zeroPointZero": 0.0,
77 "bool": true,
78 "null": null,
79 "object": {
80 "strings": ["foo", "bar"],
81 "mixed": [1, true]
82 },
83 });
84
85 testrust-analyzer cargo schemars 1.2.2 test!!(value: value.clonerust-analyzer cargo serde_json 1.0.151 value/impl#[Value][Clone]clone().())
86 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
87 .assert_allows_ser_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip().([value]);
88 }