Debian Codegraph @

examples/serialize_contract.rs

raw symbols SCIP
1 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#, JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#};
2 use serderust-analyzer cargo serde 1.0.229 crate/::{Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#};
3
4 #[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:)]
5 // The schema effectively ignores this `rename_all`, since it doesn't apply to serialization
6 #[serde(rename_all(deserialize = "PascalCase"))]
7 pub struct MyStructrust-analyzer cargo schemars 1.2.2 MyStruct# {
8 pub my_intrust-analyzer cargo schemars 1.2.2 MyStruct#my_int.: i32,
9 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(skip_deserializing)]
10 pub my_read_only_boolrust-analyzer cargo schemars 1.2.2 MyStruct#my_read_only_bool.: bool,
11 // This property is excluded from the schema
12 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(skip_serializing)]
13 pub my_write_only_boolrust-analyzer cargo schemars 1.2.2 MyStruct#my_write_only_bool.: bool,
14 // This property is excluded from the "required" properties of the schema, because it may be
15 // be skipped during serialization
16 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(skip_serializing_if = "str::is_empty")]
17 pub maybe_stringrust-analyzer cargo schemars 1.2.2 MyStruct#maybe_string.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
18 pub definitely_stringrust-analyzer cargo schemars 1.2.2 MyStruct#definitely_string.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
19 }
20
21 fn mainrust-analyzer cargo schemars 1.2.2 main().() {
22 // By default, generated schemas describe how types are deserialized.
23 // So we modify the settings here to instead generate schemas describing how it's serialized:
24 let settings = SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::defaultrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings][Default]default().().for_serializerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]for_serialize().();
25
26 let generator = settings.into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().();
27 let schema = generator.into_root_schema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]into_root_schema_for().::<MyStructrust-analyzer cargo schemars 1.2.2 MyStruct#>();
28 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_string_prettyrust-analyzer cargo serde_json 1.0.151 ser/to_string_pretty().(&schema).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
29 }