Debian Codegraph @

examples/remote_derive.rs

raw symbols SCIP
1 // Pretend that this is somebody else's crate, not a module.
2 mod other_craterust-analyzer cargo schemars 1.2.2 other_crate/ {
3 // Neither Schemars nor the other crate provides a JsonSchema impl
4 // for this struct.
5 pub struct Durationrust-analyzer cargo schemars 1.2.2 other_crate/Duration# {
6 pub secsrust-analyzer cargo schemars 1.2.2 other_crate/Duration#secs.: i64,
7 pub nanosrust-analyzer cargo schemars 1.2.2 other_crate/Duration#nanos.: i32,
8 }
9 }
10
11 ////////////////////////////////////////////////////////////////////////////////
12
13 use other_craterust-analyzer cargo schemars 1.2.2 other_crate/::Durationrust-analyzer cargo schemars 1.2.2 other_crate/Duration#;
14 use schemarsrust-analyzer cargo schemars 1.2.2 crate/::{schema_forrust-analyzer cargo schemars 1.2.2 macros/schema_for!, JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#};
15
16 // This is just a copy of the remote data structure that Schemars can use to
17 // create a suitable JsonSchema impl.
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:)]
19 #[serde(remote = "Duration")]
20 pub struct DurationDefrust-analyzer cargo schemars 1.2.2 DurationDef# {
21 pub secsrust-analyzer cargo schemars 1.2.2 DurationDef#secs.: i64,
22 pub nanosrust-analyzer cargo schemars 1.2.2 DurationDef#nanos.: i32,
23 }
24
25 // Now the remote type can be used almost like it had its own JsonSchema impl
26 // all along. The `with` attribute gives the path to the definition for the
27 // remote type. Note that the real type of the field is the remote type, not
28 // the definition type.
29 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:)]
30 pub struct Processrust-analyzer cargo schemars 1.2.2 Process# {
31 pub command_linerust-analyzer cargo schemars 1.2.2 Process#command_line.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
32 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(with = "DurationDef")]
33 pub wall_timerust-analyzer cargo schemars 1.2.2 Process#wall_time.: Durationrust-analyzer cargo schemars 1.2.2 other_crate/Duration#,
34 // Generic types must be explicitly specified with turbofix `::<>` syntax.
35 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(with = "Vec::<DurationDef>")]
36 pub durationsrust-analyzer cargo schemars 1.2.2 Process#durations.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Durationrust-analyzer cargo schemars 1.2.2 other_crate/Duration#>,
37 }
38
39 fn mainrust-analyzer cargo schemars 1.2.2 main().() {
40 let schema = schema_forrust-analyzer cargo schemars 1.2.2 macros/schema_for!!(Processrust-analyzer cargo schemars 1.2.2 Process#);
41 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().());
42 }