#[doc = r" Error types."] pub mod error { #[doc = r" Error from a TryFrom or FromStr implementation."] pub struct ConversionError(::std::borrow::Cow<'static, str>); impl ::std::error::Error for ConversionError {} impl ::std::fmt::Display for ConversionError { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> { ::std::fmt::Display::fmt(&self.0, f) } } impl ::std::fmt::Debug for ConversionError { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> { ::std::fmt::Debug::fmt(&self.0, f) } } impl From<&'static str> for ConversionError { fn from(value: &'static str) -> Self { Self(value.into()) } } impl From for ConversionError { fn from(value: String) -> Self { Self(value.into()) } } } #[doc = "Doodad"] #[doc = r""] #[doc = r"
JSON schema"] #[doc = r""] #[doc = r" ```json"] #[doc = "{"] #[doc = " \"type\": \"object\","] #[doc = " \"properties\": {"] #[doc = " \"when\": {"] #[doc = " \"default\": \"1970-01-01T00:00:00Z\","] #[doc = " \"type\": \"string\","] #[doc = " \"format\": \"date-time\""] #[doc = " }"] #[doc = " }"] #[doc = "}"] #[doc = r" ```"] #[doc = r"
"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)] pub struct Doodad { #[serde(default = "defaults::doodad_when")] pub when: chrono::DateTime, } impl From<&Doodad> for Doodad { fn from(value: &Doodad) -> Self { value.clone() } } #[doc = "MrDefaultNumbers"] #[doc = r""] #[doc = r"
JSON schema"] #[doc = r""] #[doc = r" ```json"] #[doc = "{"] #[doc = " \"type\": \"object\","] #[doc = " \"properties\": {"] #[doc = " \"little_u16\": {"] #[doc = " \"default\": 3,"] #[doc = " \"type\": \"integer\","] #[doc = " \"format\": \"uint16\","] #[doc = " \"minimum\": 1.0"] #[doc = " },"] #[doc = " \"little_u8\": {"] #[doc = " \"default\": 2,"] #[doc = " \"type\": \"integer\","] #[doc = " \"format\": \"uint8\","] #[doc = " \"minimum\": 1.0"] #[doc = " }"] #[doc = " }"] #[doc = "}"] #[doc = r" ```"] #[doc = r"
"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)] pub struct MrDefaultNumbers { #[serde(default = "defaults::default_nzu64::")] pub little_u16: std::num::NonZeroU16, #[serde(default = "defaults::default_nzu64::")] pub little_u8: std::num::NonZeroU8, } impl From<&MrDefaultNumbers> for MrDefaultNumbers { fn from(value: &MrDefaultNumbers) -> Self { value.clone() } } #[doc = "OuterThing"] #[doc = r""] #[doc = r"
JSON schema"] #[doc = r""] #[doc = r" ```json"] #[doc = "{"] #[doc = " \"type\": \"object\","] #[doc = " \"properties\": {"] #[doc = " \"thing\": {"] #[doc = " \"title\": \"ThingWithDefaults\","] #[doc = " \"default\": {"] #[doc = " \"type\": \"bee\""] #[doc = " },"] #[doc = " \"type\": \"object\","] #[doc = " \"properties\": {"] #[doc = " \"a\": {"] #[doc = " \"type\": \"string\""] #[doc = " },"] #[doc = " \"type\": {"] #[doc = " \"type\": \"string\""] #[doc = " }"] #[doc = " },"] #[doc = " \"additionalProperties\": false"] #[doc = " }"] #[doc = " }"] #[doc = "}"] #[doc = r" ```"] #[doc = r"
"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)] pub struct OuterThing { #[serde(default, skip_serializing_if = "Option::is_none")] pub thing: Option, } impl From<&OuterThing> for OuterThing { fn from(value: &OuterThing) -> Self { value.clone() } } #[doc = "TestBed"] #[doc = r""] #[doc = r"
JSON schema"] #[doc = r""] #[doc = r" ```json"] #[doc = "{"] #[doc = " \"type\": \"object\","] #[doc = " \"properties\": {"] #[doc = " \"any\": {"] #[doc = " \"default\": ["] #[doc = " ["] #[doc = " 8,"] #[doc = " 6,"] #[doc = " 7"] #[doc = " ],"] #[doc = " ["] #[doc = " 5,"] #[doc = " 3,"] #[doc = " 0,"] #[doc = " 9"] #[doc = " ]"] #[doc = " ],"] #[doc = " \"type\": \"array\","] #[doc = " \"items\": {}"] #[doc = " },"] #[doc = " \"id\": {"] #[doc = " \"default\": \"abc123-is-this-a-uuid\","] #[doc = " \"type\": \"string\","] #[doc = " \"format\": \"uuid\""] #[doc = " }"] #[doc = " }"] #[doc = "}"] #[doc = r" ```"] #[doc = r"
"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)] pub struct TestBed { #[serde(default = "defaults::test_bed_any")] pub any: Vec<::serde_json::Value>, #[serde(default = "defaults::test_bed_id")] pub id: uuid::Uuid, } impl From<&TestBed> for TestBed { fn from(value: &TestBed) -> Self { value.clone() } } #[doc = "ThingWithDefaults"] #[doc = r""] #[doc = r"
JSON schema"] #[doc = r""] #[doc = r" ```json"] #[doc = "{"] #[doc = " \"title\": \"ThingWithDefaults\","] #[doc = " \"default\": {"] #[doc = " \"type\": \"bee\""] #[doc = " },"] #[doc = " \"type\": \"object\","] #[doc = " \"properties\": {"] #[doc = " \"a\": {"] #[doc = " \"type\": \"string\""] #[doc = " },"] #[doc = " \"type\": {"] #[doc = " \"type\": \"string\""] #[doc = " }"] #[doc = " },"] #[doc = " \"additionalProperties\": false"] #[doc = "}"] #[doc = r" ```"] #[doc = r"
"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)] #[serde(deny_unknown_fields)] pub struct ThingWithDefaults { #[serde(default, skip_serializing_if = "Option::is_none")] pub a: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")] pub type_: Option, } impl From<&ThingWithDefaults> for ThingWithDefaults { fn from(value: &ThingWithDefaults) -> Self { value.clone() } } impl Default for ThingWithDefaults { fn default() -> Self { ThingWithDefaults { a: Default::default(), type_: Some("bee".to_string()), } } } #[doc = r" Generation of default values for serde."] pub mod defaults { pub(super) fn default_nzu64() -> T where T: std::convert::TryFrom, >::Error: std::fmt::Debug, { T::try_from(std::num::NonZeroU64::try_from(V).unwrap()).unwrap() } pub(super) fn doodad_when() -> chrono::DateTime { serde_json::from_str::>("\"1970-01-01T00:00:00Z\"") .unwrap() } pub(super) fn test_bed_any() -> Vec<::serde_json::Value> { vec![ serde_json::from_str::("[8,6,7]").unwrap(), serde_json::from_str::("[5,3,0,9]").unwrap(), ] } pub(super) fn test_bed_id() -> uuid::Uuid { serde_json::from_str::("\"abc123-is-this-a-uuid\"").unwrap() } } fn main() {}