| 1 | /*! |
| 2 | JSON Schema generator and settings. |
| 3 | |
| 4 | This module is useful if you want more control over how the schema generated than the [`schema_for!`] macro gives you. |
| 5 | There are two main types in this module: |
| 6 | * [`SchemaSettings`], which defines what JSON Schema features should be used when generating schemas (for example, how `Option`s should be represented). |
| 7 | * [`SchemaGenerator`], which manages the generation of a schema document. |
| 8 | */ |
| 9 | |
| 10 | use craterust-analyzer cargo schemars 1.2.2 crate/::constsrust-analyzer cargo schemars 1.2.2 consts/::meta_schemasrust-analyzer cargo schemars 1.2.2 consts/meta_schemas/; |
| 11 | use craterust-analyzer cargo schemars 1.2.2 crate/::Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#; |
| 12 | use craterust-analyzer cargo schemars 1.2.2 crate/::_alloc_preluderust-analyzer cargo schemars 1.2.2 _alloc_prelude/::*; |
| 13 | use craterust-analyzer cargo schemars 1.2.2 crate/::{transformrust-analyzer cargo schemars 1.2.2 transform/::*, JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#}; |
| 14 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::{BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#, BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#}; |
| 15 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/::Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#, fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#}; |
| 16 | use dyn_clonerust-analyzer cargo dyn-clone 1.0.20 crate/::DynClonerust-analyzer cargo dyn-clone 1.0.20 DynClone#; |
| 17 | use serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#; |
| 18 | use serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::{Maprust-analyzer cargo serde_json 1.0.151 map/Map# as JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#}; |
| 19 | |
| 20 | type CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr# = allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>; |
| 21 | |
| 22 | /// Settings to customize how Schemas are generated. |
| 23 | /// |
| 24 | /// The default settings currently conform to [JSON Schema 2020-12](https://json-schema.org/specification-links#2020-12), but this is liable to change in a future version of Schemars if support for other JSON Schema versions is added. |
| 25 | /// If you rely on generated schemas conforming to draft 2020-12, consider using the |
| 26 | /// [`SchemaSettings::draft2020_12()`] method. |
| 27 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 28 | #[non_exhaustive] |
| 29 | #[allow(clippy::struct_excessive_bools)] |
| 30 | pub struct SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 31 | /// A JSON pointer to the expected location of referenceable subschemas within the resulting |
| 32 | /// root schema. |
| 33 | /// |
| 34 | /// A single leading `#` and/or single trailing `/` are ignored. |
| 35 | /// |
| 36 | /// Defaults to `"/$defs"`. |
| 37 | pub definitions_pathrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#definitions_path.: CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#, |
| 38 | /// The URI of the meta-schema describing the structure of the generated schemas. |
| 39 | /// |
| 40 | /// Defaults to [`meta_schemas::DRAFT2020_12`] (`https://json-schema.org/draft/2020-12/schema`). |
| 41 | pub meta_schemarust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#meta_schema.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#>, |
| 42 | /// A list of [`Transform`]s that get applied to generated root schemas. |
| 43 | /// |
| 44 | /// Defaults to an empty vec (no transforms). |
| 45 | pub transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn GenTransformrust-analyzer cargo schemars 1.2.2 generate/GenTransform#>>, |
| 46 | /// Inline all subschemas instead of using references. |
| 47 | /// |
| 48 | /// Some references may still be generated in schemas for recursive types. |
| 49 | /// |
| 50 | /// Defaults to `false`. |
| 51 | pub inline_subschemasrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#inline_subschemas.: bool, |
| 52 | /// Whether the generated schemas should describe how types are serialized or *de*serialized. |
| 53 | /// |
| 54 | /// Defaults to `Contract::Deserialize`. |
| 55 | pub contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract.: Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#, |
| 56 | /// Whether to include enum variant names in their schema's `title` when using the [untagged |
| 57 | /// enum representation](https://serde.rs/enum-representations.html#untagged). |
| 58 | /// |
| 59 | /// This setting is respected by `#[derive(JsonSchema)]` on enums, but manual implementations |
| 60 | /// of `JsonSchema` may ignore this setting. |
| 61 | /// |
| 62 | /// Defaults to `false`. |
| 63 | pub untagged_enum_variant_titlesrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#untagged_enum_variant_titles.: bool, |
| 64 | } |
| 65 | |
| 66 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 67 | /// The default settings currently conform to [JSON Schema 2020-12](https://json-schema.org/specification-links#2020-12), |
| 68 | /// but this is liable to change in a future version of Schemars if support for other JSON Schema versions is added. |
| 69 | /// If you rely on generated schemas conforming to draft 2020-12, consider using [`SchemaSettings::draft2020_12()`] instead. |
| 70 | fn defaultrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings][Default]default().() -> SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 71 | SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::draft2020_12rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]draft2020_12().() |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | impl SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 76 | /// Creates `SchemaSettings` that conform to [JSON Schema Draft 7](https://json-schema.org/specification-links#draft-7). |
| 77 | #[must_use] |
| 78 | pub fn draft07rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]draft07().() -> SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 79 | SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 80 | definitions_pathrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#definitions_path.: "/definitions".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 81 | 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#(meta_schemasrust-analyzer cargo schemars 1.2.2 consts/meta_schemas/::DRAFT07rust-analyzer cargo schemars 1.2.2 consts/meta_schemas/DRAFT07..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 82 | transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 83 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ReplaceUnevaluatedPropertiesrust-analyzer cargo schemars 1.2.2 transform/ReplaceUnevaluatedProperties#), |
| 84 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(RemoveRefSiblingsrust-analyzer cargo schemars 1.2.2 transform/RemoveRefSiblings#), |
| 85 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ReplacePrefixItemsrust-analyzer cargo schemars 1.2.2 transform/ReplacePrefixItems#), |
| 86 | ], |
| 87 | inline_subschemasrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#inline_subschemas.: false, |
| 88 | contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract.: Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#, |
| 89 | untagged_enum_variant_titlesrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#untagged_enum_variant_titles.: false, |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /// Creates `SchemaSettings` that conform to [JSON Schema 2019-09](https://json-schema.org/specification-links#draft-2019-09-(formerly-known-as-draft-8)). |
| 94 | #[must_use] |
| 95 | pub fn draft2019_09rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]draft2019_09().() -> SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 96 | SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 97 | definitions_pathrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#definitions_path.: "/$defs".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 98 | 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#(meta_schemasrust-analyzer cargo schemars 1.2.2 consts/meta_schemas/::DRAFT2019_09rust-analyzer cargo schemars 1.2.2 consts/meta_schemas/DRAFT2019_09..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 99 | transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ReplacePrefixItemsrust-analyzer cargo schemars 1.2.2 transform/ReplacePrefixItems#)], |
| 100 | inline_subschemasrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#inline_subschemas.: false, |
| 101 | contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract.: Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#, |
| 102 | untagged_enum_variant_titlesrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#untagged_enum_variant_titles.: false, |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /// Creates `SchemaSettings` that conform to [JSON Schema 2020-12](https://json-schema.org/specification-links#2020-12). |
| 107 | #[must_use] |
| 108 | pub fn draft2020_12rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]draft2020_12().() -> SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 109 | SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 110 | definitions_pathrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#definitions_path.: "/$defs".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 111 | 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#(meta_schemasrust-analyzer cargo schemars 1.2.2 consts/meta_schemas/::DRAFT2020_12rust-analyzer cargo schemars 1.2.2 consts/meta_schemas/DRAFT2020_12..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 112 | transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms.: 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().(), |
| 113 | inline_subschemasrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#inline_subschemas.: false, |
| 114 | contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract.: Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#, |
| 115 | untagged_enum_variant_titlesrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#untagged_enum_variant_titles.: false, |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /// Creates `SchemaSettings` that conform to [OpenAPI 3.0](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#schema). |
| 120 | #[must_use] |
| 121 | pub fn openapi3rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]openapi3().() -> SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 122 | SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 123 | definitions_pathrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#definitions_path.: "/components/schemas".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 124 | 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#(meta_schemasrust-analyzer cargo schemars 1.2.2 consts/meta_schemas/::OPENAPI3rust-analyzer cargo schemars 1.2.2 consts/meta_schemas/OPENAPI3..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 125 | transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 126 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ReplaceUnevaluatedPropertiesrust-analyzer cargo schemars 1.2.2 transform/ReplaceUnevaluatedProperties#), |
| 127 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ReplaceBoolSchemasrust-analyzer cargo schemars 1.2.2 transform/ReplaceBoolSchemas# { |
| 128 | skip_additional_propertiesrust-analyzer cargo schemars 1.2.2 transform/ReplaceBoolSchemas#skip_additional_properties.: true, |
| 129 | }), |
| 130 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(AddNullablerust-analyzer cargo schemars 1.2.2 transform/AddNullable#::defaultrust-analyzer cargo schemars 1.2.2 transform/impl#[AddNullable][Default]default().()), |
| 131 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(RemoveRefSiblingsrust-analyzer cargo schemars 1.2.2 transform/RemoveRefSiblings#), |
| 132 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(SetSingleExamplerust-analyzer cargo schemars 1.2.2 transform/SetSingleExample#), |
| 133 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ReplaceConstValuerust-analyzer cargo schemars 1.2.2 transform/ReplaceConstValue#), |
| 134 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ReplacePrefixItemsrust-analyzer cargo schemars 1.2.2 transform/ReplacePrefixItems#), |
| 135 | ], |
| 136 | inline_subschemasrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#inline_subschemas.: false, |
| 137 | contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract.: Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#, |
| 138 | untagged_enum_variant_titlesrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#untagged_enum_variant_titles.: false, |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /// Modifies the `SchemaSettings` by calling the given function. |
| 143 | /// |
| 144 | /// # Example |
| 145 | /// ``` |
| 146 | /// use schemars::generate::{SchemaGenerator, SchemaSettings}; |
| 147 | /// |
| 148 | /// let settings = SchemaSettings::default().with(|s| { |
| 149 | /// s.meta_schema = None; |
| 150 | /// s.inline_subschemas = true; |
| 151 | /// }); |
| 152 | /// let generator = settings.into_generator(); |
| 153 | /// ``` |
| 154 | #[must_use] |
| 155 | pub fn withrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]with().(mut self, configure_fn: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings])) -> Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings] { |
| 156 | configure_fn(&mut self); |
| 157 | self |
| 158 | } |
| 159 | |
| 160 | /// Appends the given transform to the list of [transforms](SchemaSettings::transforms) for |
| 161 | /// these `SchemaSettings`. |
| 162 | #[must_use] |
| 163 | pub fn with_transformrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]with_transform().(mut self, transform: impl Transformrust-analyzer cargo schemars 1.2.2 transform/Transform# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + 'static + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#) -> Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings] { |
| 164 | self.transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(transform)); |
| 165 | self |
| 166 | } |
| 167 | |
| 168 | /// Creates a new [`SchemaGenerator`] using these settings. |
| 169 | #[must_use] |
| 170 | pub fn into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().(self) -> SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 171 | SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#::newrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]new().(self) |
| 172 | } |
| 173 | |
| 174 | /// Updates the settings to generate schemas describing how types are **deserialized**. |
| 175 | #[must_use] |
| 176 | pub fn for_deserializerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]for_deserialize().(mut self) -> Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings] { |
| 177 | self.contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract. = Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#; |
| 178 | self |
| 179 | } |
| 180 | |
| 181 | /// Updates the settings to generate schemas describing how types are **serialized**. |
| 182 | #[must_use] |
| 183 | pub fn for_serializerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]for_serialize().(mut self) -> Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings] { |
| 184 | self.contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract. = Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Serializerust-analyzer cargo schemars 1.2.2 generate/Contract#Serialize#; |
| 185 | self |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /// A setting to specify whether generated schemas should describe how types are serialized or |
| 190 | /// *de*serialized. |
| 191 | /// |
| 192 | /// This enum is marked as `#[non_exhaustive]` to reserve space to introduce further variants |
| 193 | /// in future. |
| 194 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 195 | #[allow(missing_docs)] |
| 196 | #[non_exhaustive] |
| 197 | pub enum Contractrust-analyzer cargo schemars 1.2.2 generate/Contract# { |
| 198 | Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#, |
| 199 | Serializerust-analyzer cargo schemars 1.2.2 generate/Contract#Serialize#, |
| 200 | } |
| 201 | |
| 202 | impl Contractrust-analyzer cargo schemars 1.2.2 generate/Contract# { |
| 203 | /// Returns true if `self` is the `Deserialize` contract. |
| 204 | #[must_use] |
| 205 | pub fn is_deserializerust-analyzer cargo schemars 1.2.2 generate/impl#[Contract]is_deserialize().(&self) -> bool { |
| 206 | self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize# |
| 207 | } |
| 208 | |
| 209 | /// Returns true if `self` is the `Serialize` contract. |
| 210 | #[must_use] |
| 211 | pub fn is_serializerust-analyzer cargo schemars 1.2.2 generate/impl#[Contract]is_serialize().(&self) -> bool { |
| 212 | self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().&Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Serializerust-analyzer cargo schemars 1.2.2 generate/Contract#Serialize# |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 217 | struct SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#(CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#, Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#); |
| 218 | |
| 219 | /// The main type used to generate JSON Schemas. |
| 220 | /// |
| 221 | /// # Example |
| 222 | /// ``` |
| 223 | /// use schemars::{JsonSchema, SchemaGenerator}; |
| 224 | /// |
| 225 | /// #[derive(JsonSchema)] |
| 226 | /// struct MyStruct { |
| 227 | /// foo: i32, |
| 228 | /// } |
| 229 | /// |
| 230 | /// let generator = SchemaGenerator::default(); |
| 231 | /// let schema = generator.into_root_schema_for::<MyStruct>(); |
| 232 | /// ``` |
| 233 | #[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:)] |
| 234 | pub struct SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 235 | settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings.: SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#, |
| 236 | definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions.: JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>, |
| 237 | pending_schema_idsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#pending_schema_ids.: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#<SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#>, |
| 238 | schema_id_to_namerust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#schema_id_to_name.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#, CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#>, |
| 239 | used_schema_namesrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#used_schema_names.: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#<CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#>, |
| 240 | // It's unlikely that `root_schema_id_stack` will ever contain more than one item, but it is |
| 241 | // possible, e.g. if a `json_schema()` implementation calls `generator.root_schema_for<...>()` |
| 242 | root_schema_id_stackrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#root_schema_id_stack.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#>, |
| 243 | } |
| 244 | |
| 245 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 246 | fn defaultrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator][Default]default().() -> Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator][Default] { |
| 247 | SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::defaultrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings][Default]default().().into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().() |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 252 | fn clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator][Clone]clone().(&self) -> Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator][Clone] { |
| 253 | Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator][Clone] { |
| 254 | settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings.: self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings][Clone]clone().(), |
| 255 | definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions.: self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions..clonerust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`][Clone]clone().(), |
| 256 | pending_schema_idsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#pending_schema_ids.: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().(), |
| 257 | schema_id_to_namerust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#schema_id_to_name.: 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().(), |
| 258 | used_schema_namesrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#used_schema_names.: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().(), |
| 259 | root_schema_id_stackrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#root_schema_id_stack.: 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().(), |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#> for SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 265 | fn fromrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator][`From<SchemaSettings>`]from().(settings: SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#) -> Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator][`From<SchemaSettings>`] { |
| 266 | settings.into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().() |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | impl SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 271 | /// Creates a new `SchemaGenerator` using the given settings. |
| 272 | #[must_use] |
| 273 | pub fn newrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]new().(settings: SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#) -> SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 274 | SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator# { |
| 275 | settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings., |
| 276 | definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions.: JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#::newrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]new().(), |
| 277 | pending_schema_idsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#pending_schema_ids.: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().(), |
| 278 | schema_id_to_namerust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#schema_id_to_name.: 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().(), |
| 279 | used_schema_namesrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#used_schema_names.: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T>`]new().(), |
| 280 | root_schema_id_stackrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#root_schema_id_stack.: 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().(), |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /// Borrows the [`SchemaSettings`] being used by this `SchemaGenerator`. |
| 285 | /// |
| 286 | /// # Example |
| 287 | /// ``` |
| 288 | /// use schemars::SchemaGenerator; |
| 289 | /// |
| 290 | /// let generator = SchemaGenerator::default(); |
| 291 | /// let settings = generator.settings(); |
| 292 | /// |
| 293 | /// assert_eq!(settings.inline_subschemas, false); |
| 294 | /// ``` |
| 295 | #[must_use] |
| 296 | pub fn settingsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]settings().(&self) -> &SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings# { |
| 297 | &self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings. |
| 298 | } |
| 299 | |
| 300 | /// Generates a JSON Schema for the type `T`, and returns either the schema itself or a `$ref` |
| 301 | /// schema referencing `T`'s schema. |
| 302 | /// |
| 303 | /// If `T` is not [inlined](JsonSchema::inline_schema), this will add `T`'s schema to |
| 304 | /// this generator's definitions, and return a `$ref` schema referencing that schema. |
| 305 | /// Otherwise, this method behaves identically to [`JsonSchema::json_schema`]. |
| 306 | /// |
| 307 | /// If `T`'s schema depends on any [non-inlined](JsonSchema::inline_schema) schemas, then |
| 308 | /// this method will add them to the `SchemaGenerator`'s schema definitions. |
| 309 | pub fn subschema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]subschema_for().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(&mut self) -> Schemarust-analyzer cargo schemars 1.2.2 schema/Schema# { |
| 310 | struct FindRefrust-analyzer cargo schemars 1.2.2 generate/FindRef# { |
| 311 | schemarust-analyzer cargo schemars 1.2.2 generate/FindRef#schema.: Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, |
| 312 | name_to_be_insertedrust-analyzer cargo schemars 1.2.2 generate/FindRef#name_to_be_inserted.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#>, |
| 313 | } |
| 314 | |
| 315 | /// Non-generic inner function to improve compile times. |
| 316 | fn find_refrust-analyzer cargo schemars 1.2.2 generate/find_ref().( |
| 317 | this: &mut SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#, |
| 318 | uid: &SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#, |
| 319 | inline_schema: bool, |
| 320 | schema_name: fn() -> CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#, |
| 321 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<FindRefrust-analyzer cargo schemars 1.2.2 generate/FindRef#> { |
| 322 | let return_ref = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().inline_schema |
| 323 | && (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().this.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..inline_subschemasrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#inline_subschemas. || this.pending_schema_idsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#pending_schema_ids..containsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]contains().(uid)); |
| 324 | |
| 325 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().return_ref { |
| 326 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 327 | } |
| 328 | |
| 329 | if this.root_schema_id_stackrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#root_schema_id_stack..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(uid) { |
| 330 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FindRefrust-analyzer cargo schemars 1.2.2 generate/FindRef# { |
| 331 | schemarust-analyzer cargo schemars 1.2.2 generate/FindRef#schema.: Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#::new_refrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]new_ref().("#".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()), |
| 332 | name_to_be_insertedrust-analyzer cargo schemars 1.2.2 generate/FindRef#name_to_be_inserted.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 333 | }); |
| 334 | } |
| 335 | |
| 336 | let name = this.schema_id_to_namerust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#schema_id_to_name..getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().(uid).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| { |
| 337 | let base_name = schema_name(); |
| 338 | let mut name = CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(""); |
| 339 | |
| 340 | if this.used_schema_namesrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#used_schema_names..containsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]contains().(base_name.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().()) { |
| 341 | for i in 2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom# { |
| 342 | name = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{base_name}{i}").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 343 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().this.used_schema_namesrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#used_schema_names..containsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]contains().(&name) { |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | } else { |
| 348 | name = base_name; |
| 349 | } |
| 350 | |
| 351 | this.used_schema_namesrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#used_schema_names..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Clone]clone().()); |
| 352 | this.schema_id_to_namerust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#schema_id_to_name..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(uid.clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaUid][Clone]clone().(), name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Clone]clone().()); |
| 353 | name |
| 354 | }); |
| 355 | |
| 356 | let reference = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 357 | "#{}/{}", |
| 358 | this.definitions_path_strippedrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions_path_stripped().(), |
| 359 | craterust-analyzer cargo schemars 1.2.2 crate/::encodingrust-analyzer cargo schemars 1.2.2 encoding/::encode_ref_namerust-analyzer cargo schemars 1.2.2 encoding/encode_ref_name().(&name) |
| 360 | ); |
| 361 | |
| 362 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FindRefrust-analyzer cargo schemars 1.2.2 generate/FindRef# { |
| 363 | schemarust-analyzer cargo schemars 1.2.2 generate/FindRef#schema.: Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#::new_refrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]new_ref().(reference), |
| 364 | name_to_be_insertedrust-analyzer cargo schemars 1.2.2 generate/FindRef#name_to_be_inserted.: (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().this.definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions().().contains_keyrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]contains_key().(name.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().())) |
| 365 | .then_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then_some().(name), |
| 366 | }) |
| 367 | } |
| 368 | |
| 369 | let uid = self.schema_uidrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]schema_uid().::<T>(); |
| 370 | |
| 371 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(FindRefrust-analyzer cargo schemars 1.2.2 generate/FindRef# { |
| 372 | schemarust-analyzer cargo schemars 1.2.2 generate/FindRef#schema., |
| 373 | name_to_be_insertedrust-analyzer cargo schemars 1.2.2 generate/FindRef#name_to_be_inserted., |
| 374 | }) = find_refrust-analyzer cargo schemars 1.2.2 generate/find_ref().(self, &uid, T::inline_schemarust-analyzer cargo schemars 1.2.2 JsonSchema#inline_schema().(), T::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().) |
| 375 | else { |
| 376 | return self.json_schema_internalrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]json_schema_internal().::<T>(&uid); |
| 377 | }; |
| 378 | |
| 379 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) = name_to_be_inserted { |
| 380 | self.insert_new_subschema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]insert_new_subschema_for().::<T>(name, &uid); |
| 381 | } |
| 382 | |
| 383 | schema |
| 384 | } |
| 385 | |
| 386 | fn insert_new_subschema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]insert_new_subschema_for().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(&mut self, name: CowStrrust-analyzer cargo schemars 1.2.2 generate/CowStr#, uid: &SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#) { |
| 387 | // TODO: If we've already added a schema for T with the "opposite" contract, then check |
| 388 | // whether the new schema is identical. If so, re-use the original for both contracts. |
| 389 | |
| 390 | let dummy = false.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 391 | // insert into definitions BEFORE calling json_schema to avoid infinite recursion |
| 392 | self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions..insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().(name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), dummy); |
| 393 | |
| 394 | let schema = self.json_schema_internalrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]json_schema_internal().::<T>(uid); |
| 395 | |
| 396 | self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions..insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), schema.to_valuerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]to_value().()); |
| 397 | } |
| 398 | |
| 399 | /// Borrows the collection of all [non-inlined](JsonSchema::inline_schema) schemas that |
| 400 | /// have been generated. |
| 401 | /// |
| 402 | /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the |
| 403 | /// values are the schemas themselves. |
| 404 | #[must_use] |
| 405 | pub fn definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions().(&self) -> &JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#> { |
| 406 | &self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions. |
| 407 | } |
| 408 | |
| 409 | /// Mutably borrows the collection of all [non-inlined](JsonSchema::inline_schema) |
| 410 | /// schemas that have been generated. |
| 411 | /// |
| 412 | /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the |
| 413 | /// values are the schemas themselves. |
| 414 | #[must_use] |
| 415 | pub fn definitions_mutrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions_mut().(&mut self) -> &mut JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#> { |
| 416 | &mut self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions. |
| 417 | } |
| 418 | |
| 419 | /// Returns the collection of all [non-inlined](JsonSchema::inline_schema) schemas that |
| 420 | /// have been generated, leaving an empty `Map` in its place. |
| 421 | /// |
| 422 | /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the |
| 423 | /// values are the schemas themselves. |
| 424 | /// |
| 425 | /// To apply this generator's [transforms](SchemaSettings::transforms) to each of the returned |
| 426 | /// schemas, set `apply_transforms` to `true`. |
| 427 | pub fn take_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]take_definitions().(&mut self, apply_transforms: bool) -> JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#> { |
| 428 | let mut definitions = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions.); |
| 429 | |
| 430 | if apply_transforms { |
| 431 | for schema in definitions.values_mutrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]values_mut().().flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(<&mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#>::try_fromrust-analyzer cargo schemars 1.2.2 schema/impl#[`&'a mut Schema`][`TryFrom<&'a mut Value>`]try_from().) { |
| 432 | self.apply_transformsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]apply_transforms().(schema); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | definitions |
| 437 | } |
| 438 | |
| 439 | /// Returns an iterator over the [transforms](SchemaSettings::transforms) being used by this |
| 440 | /// `SchemaGenerator`. |
| 441 | pub fn transforms_mutrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]transforms_mut().(&mut self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &mut dyn GenTransformrust-analyzer cargo schemars 1.2.2 generate/GenTransform#> { |
| 442 | self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().) |
| 443 | } |
| 444 | |
| 445 | /// Generates a JSON Schema for the type `T`. |
| 446 | /// |
| 447 | /// If `T`'s schema depends on any [non-inlined](JsonSchema::inline_schema) schemas, then |
| 448 | /// this method will include them in the returned `Schema` at the [definitions |
| 449 | /// path](SchemaSettings::definitions_path) (by default `"$defs"`). |
| 450 | pub fn root_schema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]root_schema_for().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(&mut self) -> Schemarust-analyzer cargo schemars 1.2.2 schema/Schema# { |
| 451 | let schema_uid = self.schema_uidrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]schema_uid().::<T>(); |
| 452 | self.root_schema_id_stackrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#root_schema_id_stack..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(schema_uid.clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaUid][Clone]clone().()); |
| 453 | |
| 454 | let mut schema = self.json_schema_internalrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]json_schema_internal().::<T>(&schema_uid); |
| 455 | |
| 456 | let object = schema.ensure_objectrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]ensure_object().(); |
| 457 | |
| 458 | object |
| 459 | .entryrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]entry().("title") |
| 460 | .or_insert_withrust-analyzer cargo serde_json 1.0.151 map/impl#[`Entry<'a>`]or_insert_with().(|| T::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 461 | |
| 462 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta_schema) = self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..meta_schemarust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#meta_schema..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() { |
| 463 | object.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().("$schema".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), meta_schema.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 464 | } |
| 465 | |
| 466 | self.add_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]add_definitions().(object, self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions..clonerust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`][Clone]clone().()); |
| 467 | self.apply_transformsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]apply_transforms().(&mut schema); |
| 468 | |
| 469 | self.root_schema_id_stackrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#root_schema_id_stack..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().(); |
| 470 | |
| 471 | schema |
| 472 | } |
| 473 | |
| 474 | /// Consumes `self` and generates a JSON Schema for the type `T`. |
| 475 | /// |
| 476 | /// If `T`'s schema depends on any [non-inlined](JsonSchema::inline_schema) schemas, then |
| 477 | /// this method will include them in the returned `Schema` at the [definitions |
| 478 | /// path](SchemaSettings::definitions_path) (by default `"$defs"`). |
| 479 | #[must_use] |
| 480 | pub fn into_root_schema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]into_root_schema_for().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(mut self) -> Schemarust-analyzer cargo schemars 1.2.2 schema/Schema# { |
| 481 | let schema_uid = self.schema_uidrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]schema_uid().::<T>(); |
| 482 | self.root_schema_id_stackrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#root_schema_id_stack..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(schema_uid.clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaUid][Clone]clone().()); |
| 483 | |
| 484 | let mut schema = self.json_schema_internalrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]json_schema_internal().::<T>(&schema_uid); |
| 485 | |
| 486 | let object = schema.ensure_objectrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]ensure_object().(); |
| 487 | |
| 488 | object |
| 489 | .entryrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]entry().("title") |
| 490 | .or_insert_withrust-analyzer cargo serde_json 1.0.151 map/impl#[`Entry<'a>`]or_insert_with().(|| T::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 491 | |
| 492 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta_schema) = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..meta_schemarust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#meta_schema.) { |
| 493 | object.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().("$schema".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), meta_schema.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 494 | } |
| 495 | |
| 496 | let definitions = self.take_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]take_definitions().(false); |
| 497 | self.add_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]add_definitions().(object, definitions); |
| 498 | self.apply_transformsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]apply_transforms().(&mut schema); |
| 499 | |
| 500 | schema |
| 501 | } |
| 502 | |
| 503 | /// Generates a JSON Schema for the given example value. |
| 504 | /// |
| 505 | /// If the value implements [`JsonSchema`], then prefer using the |
| 506 | /// [`root_schema_for()`](Self::root_schema_for()) function which will generally produce a |
| 507 | /// more precise schema, particularly when the value contains any enums. |
| 508 | /// |
| 509 | /// If the `Serialize` implementation of the value decides to fail, this will return an [`Err`]. |
| 510 | pub fn root_schema_for_valuerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]root_schema_for_value().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#>( |
| 511 | &mut self, |
| 512 | value: &T, |
| 513 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Errorrust-analyzer cargo serde_json 1.0.151 error/Error#> { |
| 514 | let mut schema = value.serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#serialize().(craterust-analyzer cargo schemars 1.2.2 crate/::serrust-analyzer cargo schemars 1.2.2 ser/::Serializerrust-analyzer cargo schemars 1.2.2 ser/Serializer# { |
| 515 | generatorrust-analyzer cargo schemars 1.2.2 ser/Serializer#generator.: self, |
| 516 | include_titlerust-analyzer cargo schemars 1.2.2 ser/Serializer#include_title.: true, |
| 517 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 518 | |
| 519 | let object = schema.ensure_objectrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]ensure_object().(); |
| 520 | |
| 521 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(example) = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(value) { |
| 522 | object.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().("examples".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![example].intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 523 | } |
| 524 | |
| 525 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta_schema) = self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..meta_schemarust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#meta_schema..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() { |
| 526 | object.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().("$schema".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), meta_schema.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 527 | } |
| 528 | |
| 529 | self.add_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]add_definitions().(object, self.definitionsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#definitions..clonerust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`][Clone]clone().()); |
| 530 | self.apply_transformsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]apply_transforms().(&mut schema); |
| 531 | |
| 532 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(schema) |
| 533 | } |
| 534 | |
| 535 | /// Consumes `self` and generates a JSON Schema for the given example value. |
| 536 | /// |
| 537 | /// If the value implements [`JsonSchema`], then prefer using the |
| 538 | /// [`into_root_schema_for()!`](Self::into_root_schema_for()) function which will generally |
| 539 | /// produce a more precise schema, particularly when the value contains any enums. |
| 540 | /// |
| 541 | /// If the `Serialize` implementation of the value decides to fail, this will return an [`Err`]. |
| 542 | pub fn into_root_schema_for_valuerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]into_root_schema_for_value().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#>( |
| 543 | mut self, |
| 544 | value: &T, |
| 545 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Errorrust-analyzer cargo serde_json 1.0.151 error/Error#> { |
| 546 | let mut schema = value.serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#serialize().(craterust-analyzer cargo schemars 1.2.2 crate/::serrust-analyzer cargo schemars 1.2.2 ser/::Serializerrust-analyzer cargo schemars 1.2.2 ser/Serializer# { |
| 547 | generatorrust-analyzer cargo schemars 1.2.2 ser/Serializer#generator.: &mut self, |
| 548 | include_titlerust-analyzer cargo schemars 1.2.2 ser/Serializer#include_title.: true, |
| 549 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 550 | |
| 551 | let object = schema.ensure_objectrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]ensure_object().(); |
| 552 | |
| 553 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(example) = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(value) { |
| 554 | object.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().("examples".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![example].intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 555 | } |
| 556 | |
| 557 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta_schema) = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..meta_schemarust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#meta_schema.) { |
| 558 | object.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]insert().("$schema".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), meta_schema.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 559 | } |
| 560 | |
| 561 | let definitions = self.take_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]take_definitions().(false); |
| 562 | self.add_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]add_definitions().(object, definitions); |
| 563 | self.apply_transformsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]apply_transforms().(&mut schema); |
| 564 | |
| 565 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(schema) |
| 566 | } |
| 567 | |
| 568 | /// Returns a reference to the [contract](SchemaSettings::contract) for the settings on this |
| 569 | /// `SchemaGenerator`. |
| 570 | /// |
| 571 | /// This specifies whether generated schemas describe serialize or *de*serialize behaviour. |
| 572 | #[must_use] |
| 573 | pub fn contractrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]contract().(&self) -> &Contractrust-analyzer cargo schemars 1.2.2 generate/Contract# { |
| 574 | &self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract. |
| 575 | } |
| 576 | |
| 577 | fn json_schema_internalrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]json_schema_internal().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(&mut self, uid: &SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#) -> Schemarust-analyzer cargo schemars 1.2.2 schema/Schema# { |
| 578 | let did_add = self.pending_schema_idsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#pending_schema_ids..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]insert().(uid.clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaUid][Clone]clone().()); |
| 579 | |
| 580 | let schema = T::json_schemarust-analyzer cargo schemars 1.2.2 JsonSchema#json_schema().(self); |
| 581 | |
| 582 | if did_add { |
| 583 | self.pending_schema_idsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#pending_schema_ids..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]remove().(uid); |
| 584 | } |
| 585 | |
| 586 | schema |
| 587 | } |
| 588 | |
| 589 | fn add_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]add_definitions().( |
| 590 | &mut self, |
| 591 | schema_object: &mut JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>, |
| 592 | mut definitions: JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>, |
| 593 | ) { |
| 594 | if definitions.is_emptyrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]is_empty().() { |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | let pointer = self.definitions_path_strippedrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions_path_stripped().(); |
| 599 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(target) = json_pointer_mutrust-analyzer cargo schemars 1.2.2 generate/json_pointer_mut().(schema_object, pointer, true) else { |
| 600 | return; |
| 601 | }; |
| 602 | |
| 603 | target.appendrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]append().(&mut definitions); |
| 604 | } |
| 605 | |
| 606 | fn apply_transformsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]apply_transforms().(&mut self, schema: &mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#) { |
| 607 | for transform in self.transforms_mutrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]transforms_mut().() { |
| 608 | transform.transformrust-analyzer cargo schemars 1.2.2 transform/Transform#transform().(schema); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /// Returns `self.settings.definitions_path` as a plain JSON pointer to the definitions object, |
| 613 | /// i.e. without a leading '#' or trailing '/' |
| 614 | pub(craterust-analyzer cargo schemars 1.2.2 crate/) fn definitions_path_strippedrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]definitions_path_stripped().(&self) -> &str { |
| 615 | let path = &self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..definitions_pathrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#definitions_path.; |
| 616 | let path = path.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('#').unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(path); |
| 617 | path.strip_suffixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_suffix().('/').unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(path) |
| 618 | } |
| 619 | |
| 620 | fn schema_uidrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]schema_uid().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# + JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(&self) -> SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid# { |
| 621 | SchemaUidrust-analyzer cargo schemars 1.2.2 generate/SchemaUid#(T::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().(), self.settingsrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#settings..contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract..clonerust-analyzer cargo schemars 1.2.2 generate/impl#[Contract][Clone]clone().()) |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | fn json_pointer_mutrust-analyzer cargo schemars 1.2.2 generate/json_pointer_mut().<'a>( |
| 626 | mut object: &'a mut JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>, |
| 627 | pointer: &str, |
| 628 | create_if_missing: bool, |
| 629 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a mut JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>> { |
| 630 | use serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::maprust-analyzer cargo serde_json 1.0.151 map/::Entryrust-analyzer cargo serde_json 1.0.151 map/Entry#; |
| 631 | |
| 632 | let pointer = pointer.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('/')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 633 | if pointer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 634 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(object); |
| 635 | } |
| 636 | |
| 637 | for mut segment in pointer.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('/') { |
| 638 | let replaced: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 639 | if segment.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('~') { |
| 640 | replaced = segment.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("~1", "/").replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("~0", "~"); |
| 641 | segment = &replaced; |
| 642 | } |
| 643 | |
| 644 | let next_value = match object.entryrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]entry().(segment) { |
| 645 | Entryrust-analyzer cargo serde_json 1.0.151 map/Entry#::Occupiedrust-analyzer cargo serde_json 1.0.151 map/Entry#Occupied#(o) => o.into_mutrust-analyzer cargo serde_json 1.0.151 map/impl#[`OccupiedEntry<'a>`]into_mut().(), |
| 646 | Entryrust-analyzer cargo serde_json 1.0.151 map/Entry#::Vacantrust-analyzer cargo serde_json 1.0.151 map/Entry#Vacant#(v) if create_if_missing => v.insertrust-analyzer cargo serde_json 1.0.151 map/impl#[`VacantEntry<'a>`]insert().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Objectrust-analyzer cargo serde_json 1.0.151 value/Value#Object#(JsonMaprust-analyzer cargo serde_json 1.0.151 map/Map#::newrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]new().())), |
| 647 | Entryrust-analyzer cargo serde_json 1.0.151 map/Entry#::Vacantrust-analyzer cargo serde_json 1.0.151 map/Entry#Vacant#(_) => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 648 | }; |
| 649 | |
| 650 | object = next_value.as_object_mutrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_object_mut().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 651 | } |
| 652 | |
| 653 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(object) |
| 654 | } |
| 655 | |
| 656 | /// A [`Transform`] which implements additional traits required to be included in a |
| 657 | /// [`SchemaSettings`]. |
| 658 | /// |
| 659 | /// You will rarely need to use this trait directly as it is automatically implemented for any type |
| 660 | /// which implements all of: |
| 661 | /// - [`Transform`] |
| 662 | /// - [`std::any::Any`] (implemented for all `'static` types) |
| 663 | /// - [`std::clone::Clone`] |
| 664 | /// - [`std::marker::Send`] |
| 665 | /// |
| 666 | /// # Example |
| 667 | /// ``` |
| 668 | /// use schemars::transform::Transform; |
| 669 | /// use schemars::generate::GenTransform; |
| 670 | /// |
| 671 | /// #[derive(Debug, Clone)] |
| 672 | /// struct MyTransform; |
| 673 | /// |
| 674 | /// impl Transform for MyTransform { |
| 675 | /// fn transform(&mut self, schema: &mut schemars::Schema) { |
| 676 | /// todo!() |
| 677 | /// } |
| 678 | /// } |
| 679 | /// |
| 680 | /// let v: &dyn GenTransform = &MyTransform; |
| 681 | /// assert!(v.is::<MyTransform>()); |
| 682 | /// ``` |
| 683 | pub trait GenTransformrust-analyzer cargo schemars 1.2.2 generate/GenTransform#: Transformrust-analyzer cargo schemars 1.2.2 transform/Transform# + DynClonerust-analyzer cargo dyn-clone 1.0.20 DynClone# + Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# { |
| 684 | #[deprecated = "Only to support pre-1.86 rustc"] |
| 685 | #[doc(hidden)] |
| 686 | fn _as_anyrust-analyzer cargo schemars 1.2.2 generate/GenTransform#_as_any().(&self) -> &dyn Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#; |
| 687 | |
| 688 | #[deprecated = "Only to support pre-1.86 rustc"] |
| 689 | #[doc(hidden)] |
| 690 | fn _as_any_mutrust-analyzer cargo schemars 1.2.2 generate/GenTransform#_as_any_mut().(&mut self) -> &mut dyn Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#; |
| 691 | |
| 692 | #[deprecated = "Only to support pre-1.86 rustc"] |
| 693 | #[doc(hidden)] |
| 694 | fn _into_anyrust-analyzer cargo schemars 1.2.2 generate/GenTransform#_into_any().(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Self>) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#>; |
| 695 | } |
| 696 | |
| 697 | #[allow(deprecated, clippy::used_underscore_items)] |
| 698 | impl dyn GenTransformrust-analyzer cargo schemars 1.2.2 generate/GenTransform# { |
| 699 | /// Returns `true` if the inner transform is of type `T`. |
| 700 | #[must_use] |
| 701 | pub fn isrust-analyzer cargo schemars 1.2.2 generate/impl#[`dyn GenTransform + 'static`]is().<T: Transformrust-analyzer cargo schemars 1.2.2 transform/Transform# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(&self) -> bool { |
| 702 | self._as_anyrust-analyzer cargo schemars 1.2.2 generate/GenTransform#_as_any().().isrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/impl#[`dyn Any + 'static`]is().::<T>() |
| 703 | } |
| 704 | |
| 705 | /// Returns some reference to the inner transform if it is of type `T`, or |
| 706 | /// `None` if it isn't. |
| 707 | /// |
| 708 | /// # Example |
| 709 | /// To remove a specific transform from an instance of `SchemaSettings`: |
| 710 | /// ``` |
| 711 | /// use schemars::generate::SchemaSettings; |
| 712 | /// use schemars::transform::ReplaceBoolSchemas; |
| 713 | /// |
| 714 | /// let mut settings = SchemaSettings::openapi3(); |
| 715 | /// let original_len = settings.transforms.len(); |
| 716 | /// |
| 717 | /// settings.transforms.retain(|t| !t.is::<ReplaceBoolSchemas>()); |
| 718 | /// |
| 719 | /// assert_eq!(settings.transforms.len(), original_len - 1); |
| 720 | /// ``` |
| 721 | #[must_use] |
| 722 | pub fn downcast_refrust-analyzer cargo schemars 1.2.2 generate/impl#[`dyn GenTransform + 'static`]downcast_ref().<T: Transformrust-analyzer cargo schemars 1.2.2 transform/Transform# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&T> { |
| 723 | self._as_anyrust-analyzer cargo schemars 1.2.2 generate/GenTransform#_as_any().().downcast_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/impl#[`dyn Any + 'static`]downcast_ref().::<T>() |
| 724 | } |
| 725 | |
| 726 | /// Returns some mutable reference to the inner transform if it is of type `T`, or |
| 727 | /// `None` if it isn't. |
| 728 | /// |
| 729 | /// # Example |
| 730 | /// To modify a specific transform in an instance of `SchemaSettings`: |
| 731 | /// ``` |
| 732 | /// use schemars::generate::SchemaSettings; |
| 733 | /// use schemars::transform::ReplaceBoolSchemas; |
| 734 | /// |
| 735 | /// let mut settings = SchemaSettings::openapi3(); |
| 736 | /// for t in &mut settings.transforms { |
| 737 | /// if let Some(replace_bool_schemas) = t.downcast_mut::<ReplaceBoolSchemas>() { |
| 738 | /// replace_bool_schemas.skip_additional_properties = false; |
| 739 | /// } |
| 740 | /// } |
| 741 | /// ``` |
| 742 | #[must_use] |
| 743 | pub fn downcast_mutrust-analyzer cargo schemars 1.2.2 generate/impl#[`dyn GenTransform + 'static`]downcast_mut().<T: Transformrust-analyzer cargo schemars 1.2.2 transform/Transform# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut T> { |
| 744 | self._as_any_mutrust-analyzer cargo schemars 1.2.2 generate/GenTransform#_as_any_mut().().downcast_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/impl#[`dyn Any + 'static`]downcast_mut().::<T>() |
| 745 | } |
| 746 | |
| 747 | /// Attempts to downcast the box to a concrete type. |
| 748 | /// |
| 749 | /// If the inner transform is not of type `T`, this returns `self` wrapped in an `Err` so that |
| 750 | /// it can still be used. |
| 751 | #[allow(clippy::missing_panics_doc)] // should never panic - `is()` ensures that downcast succeeds |
| 752 | pub fn downcastrust-analyzer cargo schemars 1.2.2 generate/impl#[`dyn GenTransform + 'static`]downcast().<T: Transformrust-analyzer cargo schemars 1.2.2 transform/Transform# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>( |
| 753 | self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[`dyn GenTransform + 'static`]>, |
| 754 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<T>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[`dyn GenTransform + 'static`]>> { |
| 755 | if self.isrust-analyzer cargo schemars 1.2.2 generate/impl#[`dyn GenTransform + 'static`]is().::<T>() { |
| 756 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self._into_anyrust-analyzer cargo schemars 1.2.2 generate/GenTransform#_into_any().().downcastrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/convert/impl#[`Box<dyn Any + 'static, A>`]downcast().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 757 | } else { |
| 758 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(self) |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | dyn_clonerust-analyzer cargo dyn-clone 1.0.20 crate/::clone_trait_objectrust-analyzer cargo dyn-clone 1.0.20 macros/clone_trait_object!!(GenTransformrust-analyzer cargo schemars 1.2.2 generate/GenTransform#); |
| 764 | |
| 765 | impl<T> GenTransformrust-analyzer cargo schemars 1.2.2 generate/GenTransform# for T |
| 766 | where |
| 767 | T: Transformrust-analyzer cargo schemars 1.2.2 transform/Transform# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, |
| 768 | { |
| 769 | fn _as_anyrust-analyzer cargo schemars 1.2.2 generate/impl#[T][GenTransform]_as_any().(&self) -> &dyn Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# { |
| 770 | self |
| 771 | } |
| 772 | |
| 773 | fn _as_any_mutrust-analyzer cargo schemars 1.2.2 generate/impl#[T][GenTransform]_as_any_mut().(&mut self) -> &mut dyn Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any# { |
| 774 | self |
| 775 | } |
| 776 | |
| 777 | fn _into_anyrust-analyzer cargo schemars 1.2.2 generate/impl#[T][GenTransform]_into_any().(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo schemars 1.2.2 generate/impl#[T][GenTransform]>) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#> { |
| 778 | self |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn GenTransformrust-analyzer cargo schemars 1.2.2 generate/GenTransform#> { |
| 783 | fn fmtrust-analyzer cargo schemars 1.2.2 generate/impl#[`Box<dyn GenTransform + 'static>`][Debug]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 784 | #[allow(clippy::used_underscore_items)] |
| 785 | self._debug_type_namerust-analyzer cargo schemars 1.2.2 transform/Transform#_debug_type_name().(f) |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | fn _assert_sendrust-analyzer cargo schemars 1.2.2 generate/_assert_send().() { |
| 790 | fn assertrust-analyzer cargo schemars 1.2.2 generate/assert().<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>() {} |
| 791 | |
| 792 | assertrust-analyzer cargo schemars 1.2.2 generate/assert().::<SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#>(); |
| 793 | assertrust-analyzer cargo schemars 1.2.2 generate/assert().::<SchemaGeneratorrust-analyzer cargo schemars 1.2.2 generate/SchemaGenerator#>(); |
| 794 | } |