Debian Codegraph @

tests/integration/default.rs

raw symbols SCIP
1 use craterust-analyzer cargo schemars 1.2.2 crate/::preluderust-analyzer cargo schemars 1.2.2 prelude/::*;
2
3 #[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:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
4 #[serde(default)]
5 struct MyStructrust-analyzer cargo schemars 1.2.2 default/MyStruct# {
6 integerrust-analyzer cargo schemars 1.2.2 default/MyStruct#integer.: u32,
7 booleanrust-analyzer cargo schemars 1.2.2 default/MyStruct#boolean.: bool,
8 option_stringrust-analyzer cargo schemars 1.2.2 default/MyStruct#option_string.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
9 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(skip_serializing_if = "str::is_empty")]
10 string_skip_emptyrust-analyzer cargo schemars 1.2.2 default/MyStruct#string_skip_empty.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
11 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(with = "struct_2_as_str")]
12 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(with = "str", pattern(r"^\d+ (true|false)$"))]
13 struct2rust-analyzer cargo schemars 1.2.2 default/MyStruct#struct2.: MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2#,
14 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(skip_serializing)]
15 not_serializerust-analyzer cargo schemars 1.2.2 default/MyStruct#not_serialize.: NotSerializerust-analyzer cargo schemars 1.2.2 default/NotSerialize#,
16 }
17
18 #[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:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
19 #[serde(default = "ten_and_true")]
20 struct MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2# {
21 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(default = "six")]
22 integerrust-analyzer cargo schemars 1.2.2 default/MyStruct2#integer.: u32,
23 booleanrust-analyzer cargo schemars 1.2.2 default/MyStruct2#boolean.: bool,
24 }
25
26 #[allow(dead_code)]
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:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
28 struct NotSerializerust-analyzer cargo schemars 1.2.2 default/NotSerialize#(i8);
29
30 mod struct_2_as_strrust-analyzer cargo schemars 1.2.2 default/struct_2_as_str/ {
31 use superrust-analyzer cargo schemars 1.2.2 default/::MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2#;
32
33 pub(superrust-analyzer cargo schemars 1.2.2 default/) fn serializerust-analyzer cargo schemars 1.2.2 default/struct_2_as_str/serialize().<S>(value: &MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2#, ser: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#>
34 where
35 S: serderust-analyzer cargo serde 1.0.229 crate/::Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#,
36 {
37 ser.collect_strrust-analyzer cargo serde_core 1.0.229 ser/Serializer#collect_str().(&format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("{} {}", value.integerrust-analyzer cargo schemars 1.2.2 default/MyStruct2#integer., value.booleanrust-analyzer cargo schemars 1.2.2 default/MyStruct2#boolean.))
38 }
39
40 pub(superrust-analyzer cargo schemars 1.2.2 default/) fn deserializerust-analyzer cargo schemars 1.2.2 default/struct_2_as_str/deserialize().<'de, D>(deser: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2#, D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#>
41 where
42 D: serderust-analyzer cargo serde 1.0.229 crate/::Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>,
43 {
44 use serderust-analyzer cargo serde 1.0.229 crate/::derust-analyzer cargo serde_core 1.0.229 de/::{Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Errorrust-analyzer cargo serde_core 1.0.229 de/Error#};
45 let error = || Errorrust-analyzer cargo serde_core 1.0.229 de/Error#::customrust-analyzer cargo serde_core 1.0.229 de/Error#custom().("invalid string");
46
47 let (i, b) = <&str>::deserializerust-analyzer cargo serde_core 1.0.229 de/impls/impl#[`&'a str`][`Deserialize<'de>`]deserialize().(deser)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
48 .split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(' ')
49 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(error)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch().;
50
51 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2# {
52 integerrust-analyzer cargo schemars 1.2.2 default/MyStruct2#integer.: i.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| error())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch().,
53 booleanrust-analyzer cargo schemars 1.2.2 default/MyStruct2#boolean.: b.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| error())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch().,
54 })
55 }
56 }
57
58 fn ten_and_truerust-analyzer cargo schemars 1.2.2 default/ten_and_true().() -> MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2# {
59 MyStruct2rust-analyzer cargo schemars 1.2.2 default/MyStruct2# {
60 integerrust-analyzer cargo schemars 1.2.2 default/MyStruct2#integer.: 10,
61 booleanrust-analyzer cargo schemars 1.2.2 default/MyStruct2#boolean.: true,
62 }
63 }
64
65 fn sixrust-analyzer cargo schemars 1.2.2 default/six().() -> u32 {
66 6
67 }
68
69 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
70 fn default_fieldsrust-analyzer cargo schemars 1.2.2 default/default_fields().() {
71 testrust-analyzer cargo schemars 1.2.2 test!!(MyStructrust-analyzer cargo schemars 1.2.2 default/MyStruct#)
72 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
73 .assert_allows_ser_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip().([
74 MyStructrust-analyzer cargo schemars 1.2.2 default/MyStruct#::defaultrust-analyzer cargo schemars 1.2.2 default/impl#[MyStruct][Default]default().(),
75 MyStructrust-analyzer cargo schemars 1.2.2 default/MyStruct# {
76 integerrust-analyzer cargo schemars 1.2.2 default/MyStruct#integer.: 123,
77 booleanrust-analyzer cargo schemars 1.2.2 default/MyStruct#boolean.: true,
78 option_stringrust-analyzer cargo schemars 1.2.2 default/MyStruct#option_string.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
79 string_skip_emptyrust-analyzer cargo schemars 1.2.2 default/MyStruct#string_skip_empty.: "test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
80 struct2rust-analyzer cargo schemars 1.2.2 default/MyStruct#struct2.: ten_and_truerust-analyzer cargo schemars 1.2.2 default/ten_and_true().(),
81 not_serializerust-analyzer cargo schemars 1.2.2 default/MyStruct#not_serialize.: NotSerializerust-analyzer cargo schemars 1.2.2 default/NotSerialize#(42),
82 },
83 ])
84 .assert_allows_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_de_roundtrip().([
85 jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!({}),
86 jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!({ "not_serialize": 127 })
87 ])
88 .assert_rejects_derust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_rejects_de().([
89 jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!({ "not_serialize": "a string" })
90 ])
91 .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_values_exceptrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values_except().(
92 Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::is_arrayrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]is_array().,
93 "structs with `#derive(Deserialize)` can technically be deserialized from sequences, but that's not intended to be used via JSON, so schemars ignores it",
94 ));
95 }