#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Dosage {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub modifier_extension: Vec<super::extension::Extension>,
pub sequence: Option<super::primitives::Integer>,
pub text: Option<super::primitives::String>,
pub additional_instruction: Vec<super::codeable_concept::CodeableConcept>,
pub patient_instruction: Option<super::primitives::String>,
pub timing: Option<super::timing::Timing>,
pub as_needed: Option<DosageAsNeeded>,
pub site: Option<super::codeable_concept::CodeableConcept>,
pub route: Option<super::codeable_concept::CodeableConcept>,
pub method: Option<super::codeable_concept::CodeableConcept>,
pub dose_and_rate: Vec<DosageDoseAndRate>,
pub max_dose_per_period: Option<super::ratio::Ratio>,
pub max_dose_per_administration: Option<super::quantity::Quantity>,
pub max_dose_per_lifetime: Option<super::quantity::Quantity>,
}
impl super::super::codec::Json for Dosage {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
serde_json::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(serde_json::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
serde_json::Value::Array(items),
);
}
if !self.modifier_extension.is_empty() {
let mut items = Vec::with_capacity(self.modifier_extension.len());
for item in &self.modifier_extension {
items.push(serde_json::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("modifierExtension"),
serde_json::Value::Array(items),
);
}
if let Some(item) = &self.sequence {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("sequence"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_sequence"), e);
}
}
if let Some(item) = &self.text {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("text"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_text"), e);
}
}
if !self.additional_instruction.is_empty() {
let mut items = Vec::with_capacity(self.additional_instruction.len());
for item in &self.additional_instruction {
items.push(serde_json::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("additionalInstruction"),
serde_json::Value::Array(items),
);
}
if let Some(item) = &self.patient_instruction {
if let Some(v) = super::super::codec::Primitive::value_json(item)? {
object.insert(std::string::String::from("patientInstruction"), v);
}
if let Some(e) = super::super::codec::Primitive::element_json(item)? {
object.insert(std::string::String::from("_patientInstruction"), e);
}
}
if let Some(item) = &self.timing {
object.insert(
std::string::String::from("timing"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.as_needed {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("asNeeded{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_asNeeded{suffix}"), element);
}
}
if let Some(item) = &self.site {
object.insert(
std::string::String::from("site"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.route {
object.insert(
std::string::String::from("route"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.method {
object.insert(
std::string::String::from("method"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if !self.dose_and_rate.is_empty() {
let mut items = Vec::with_capacity(self.dose_and_rate.len());
for item in &self.dose_and_rate {
items.push(serde_json::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("doseAndRate"),
serde_json::Value::Array(items),
);
}
if let Some(item) = &self.max_dose_per_period {
object.insert(
std::string::String::from("maxDosePerPeriod"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.max_dose_per_administration {
object.insert(
std::string::String::from("maxDosePerAdministration"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.max_dose_per_lifetime {
object.insert(
std::string::String::from("maxDosePerLifetime"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&serde_json::Value> = None;
let mut raw_extension: Option<&serde_json::Value> = None;
let mut raw_modifier_extension: Option<&serde_json::Value> = None;
let mut raw_sequence: Option<&serde_json::Value> = None;
let mut raw_sequence_element: Option<&serde_json::Value> = None;
let mut raw_text: Option<&serde_json::Value> = None;
let mut raw_text_element: Option<&serde_json::Value> = None;
let mut raw_additional_instruction: Option<&serde_json::Value> = None;
let mut raw_patient_instruction: Option<&serde_json::Value> = None;
let mut raw_patient_instruction_element: Option<&serde_json::Value> = None;
let mut raw_timing: Option<&serde_json::Value> = None;
let mut raw_as_needed = super::super::codec::ChoiceSlot::default();
let mut raw_site: Option<&serde_json::Value> = None;
let mut raw_route: Option<&serde_json::Value> = None;
let mut raw_method: Option<&serde_json::Value> = None;
let mut raw_dose_and_rate: Option<&serde_json::Value> = None;
let mut raw_max_dose_per_period: Option<&serde_json::Value> = None;
let mut raw_max_dose_per_administration: Option<&serde_json::Value> = None;
let mut raw_max_dose_per_lifetime: Option<&serde_json::Value> = None;
for (key, value) in object {
match key.as_str() {
"id" => raw_id = Some(value),
"extension" => raw_extension = Some(value),
"modifierExtension" => raw_modifier_extension = Some(value),
"sequence" => raw_sequence = Some(value),
"_sequence" => raw_sequence_element = Some(value),
"text" => raw_text = Some(value),
"_text" => raw_text_element = Some(value),
"additionalInstruction" => raw_additional_instruction = Some(value),
"patientInstruction" => raw_patient_instruction = Some(value),
"_patientInstruction" => raw_patient_instruction_element = Some(value),
"timing" => raw_timing = Some(value),
"asNeededBoolean" => {
raw_as_needed.value("Boolean", value, path)?;
}
"_asNeededBoolean" => {
raw_as_needed.element("Boolean", value, path)?;
}
"asNeededCodeableConcept" => {
raw_as_needed.value("CodeableConcept", value, path)?;
}
"_asNeededCodeableConcept" => {
raw_as_needed.element("CodeableConcept", value, path)?;
}
"site" => raw_site = Some(value),
"route" => raw_route = Some(value),
"method" => raw_method = Some(value),
"doseAndRate" => raw_dose_and_rate = Some(value),
"maxDosePerPeriod" => raw_max_dose_per_period = Some(value),
"maxDosePerAdministration" => raw_max_dose_per_administration = Some(value),
"maxDosePerLifetime" => raw_max_dose_per_lifetime = Some(value),
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let mut field_modifier_extension = Vec::new();
if let Some(raw) = raw_modifier_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_modifier_extension.push(path.with_index(
"modifierExtension",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_sequence = match (raw_sequence, raw_sequence_element) {
(None, None) => None,
(value, element) => Some(path.with("sequence", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_text = match (raw_text, raw_text_element) {
(None, None) => None,
(value, element) => Some(path.with("text", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let mut field_additional_instruction = Vec::new();
if let Some(raw) = raw_additional_instruction {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_additional_instruction.push(path.with_index(
"additionalInstruction",
index,
|path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
},
)?);
}
}
let field_patient_instruction =
match (raw_patient_instruction, raw_patient_instruction_element) {
(None, None) => None,
(value, element) => Some(path.with("patientInstruction", |path| {
super::super::codec::Primitive::from_json_parts(value, element, path)
})?),
};
let field_timing = raw_timing
.map(|value| {
path.with("timing", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_as_needed = match raw_as_needed.suffix {
None => None,
Some(suffix) => Some(path.with("asNeeded", |path| {
DosageAsNeeded::from_json_parts(
suffix,
raw_as_needed.value,
raw_as_needed.element,
path,
)
})?),
};
let field_site = raw_site
.map(|value| {
path.with("site", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_route = raw_route
.map(|value| {
path.with("route", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_method = raw_method
.map(|value| {
path.with("method", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let mut field_dose_and_rate = Vec::new();
if let Some(raw) = raw_dose_and_rate {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_dose_and_rate.push(path.with_index("doseAndRate", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_max_dose_per_period = raw_max_dose_per_period
.map(|value| {
path.with("maxDosePerPeriod", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_max_dose_per_administration = raw_max_dose_per_administration
.map(|value| {
path.with("maxDosePerAdministration", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_max_dose_per_lifetime = raw_max_dose_per_lifetime
.map(|value| {
path.with("maxDosePerLifetime", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
Ok(Self {
id: field_id,
extension: field_extension,
modifier_extension: field_modifier_extension,
sequence: field_sequence,
text: field_text,
additional_instruction: field_additional_instruction,
patient_instruction: field_patient_instruction,
timing: field_timing,
as_needed: field_as_needed,
site: field_site,
route: field_route,
method: field_method,
dose_and_rate: field_dose_and_rate,
max_dose_per_period: field_max_dose_per_period,
max_dose_per_administration: field_max_dose_per_administration,
max_dose_per_lifetime: field_max_dose_per_lifetime,
})
}
}
impl serde::Serialize for Dosage {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
super::super::codec::Json::to_json(self)
.map_err(serde::ser::Error::custom)?
.serialize(serializer)
}
}
impl<'de> serde::Deserialize<'de> for Dosage {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let mut path = super::super::codec::Path::root("Dosage");
let object =
super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DosageAsNeeded {
Boolean(super::primitives::Boolean),
CodeableConcept(super::codeable_concept::CodeableConcept),
}
impl DosageAsNeeded {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<serde_json::Value>,
Option<serde_json::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Boolean(inner) => Ok((
"Boolean",
super::super::codec::Primitive::value_json(inner)?,
super::super::codec::Primitive::element_json(inner)?,
)),
Self::CodeableConcept(inner) => Ok((
"CodeableConcept",
Some(serde_json::Value::Object(
super::super::codec::Json::to_json(inner)?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&serde_json::Value>,
element: Option<&serde_json::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Boolean" => Ok(Self::Boolean(
super::super::codec::Primitive::from_json_parts(value, element, path)?,
)),
"CodeableConcept" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::CodeableConcept(inner))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct DosageDoseAndRate {
pub id: Option<std::string::String>,
pub extension: Vec<super::extension::Extension>,
pub r#type: Option<super::codeable_concept::CodeableConcept>,
pub dose: Option<DosageDoseAndRateDose>,
pub rate: Option<DosageDoseAndRateRate>,
}
impl super::super::codec::Json for DosageDoseAndRate {
fn to_json(&self) -> Result<super::super::codec::Object, super::super::codec::EncodeError> {
let mut object = super::super::codec::Object::new();
if let Some(v) = &self.id {
object.insert(
std::string::String::from("id"),
serde_json::Value::String(v.clone()),
);
}
if !self.extension.is_empty() {
let mut items = Vec::with_capacity(self.extension.len());
for item in &self.extension {
items.push(serde_json::Value::Object(
super::super::codec::Json::to_json(item)?,
));
}
object.insert(
std::string::String::from("extension"),
serde_json::Value::Array(items),
);
}
if let Some(item) = &self.r#type {
object.insert(
std::string::String::from("type"),
serde_json::Value::Object(super::super::codec::Json::to_json(item)?),
);
}
if let Some(item) = &self.dose {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("dose{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_dose{suffix}"), element);
}
}
if let Some(item) = &self.rate {
let (suffix, value, element) = item.to_json_parts()?;
if let Some(value) = value {
object.insert(format!("rate{suffix}"), value);
}
if let Some(element) = element {
object.insert(format!("_rate{suffix}"), element);
}
}
Ok(object)
}
fn from_json(
object: &super::super::codec::Object,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
let mut raw_id: Option<&serde_json::Value> = None;
let mut raw_extension: Option<&serde_json::Value> = None;
let mut raw_type: Option<&serde_json::Value> = None;
let mut raw_dose = super::super::codec::ChoiceSlot::default();
let mut raw_rate = super::super::codec::ChoiceSlot::default();
for (key, value) in object {
match key.as_str() {
"id" => raw_id = Some(value),
"extension" => raw_extension = Some(value),
"type" => raw_type = Some(value),
"doseRange" => {
raw_dose.value("Range", value, path)?;
}
"_doseRange" => {
raw_dose.element("Range", value, path)?;
}
"doseQuantity" => {
raw_dose.value("Quantity", value, path)?;
}
"_doseQuantity" => {
raw_dose.element("Quantity", value, path)?;
}
"rateRatio" => {
raw_rate.value("Ratio", value, path)?;
}
"_rateRatio" => {
raw_rate.element("Ratio", value, path)?;
}
"rateRange" => {
raw_rate.value("Range", value, path)?;
}
"_rateRange" => {
raw_rate.element("Range", value, path)?;
}
"rateQuantity" => {
raw_rate.value("Quantity", value, path)?;
}
"_rateQuantity" => {
raw_rate.element("Quantity", value, path)?;
}
other => {
return path.with(other, |path| {
Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty))
});
}
}
}
let field_id = raw_id
.map(|value| {
path.with("id", |path| {
let value = super::super::codec::expect_single(value, path)?;
super::super::codec::expect_string(value, path)
})
})
.transpose()?;
let mut field_extension = Vec::new();
if let Some(raw) = raw_extension {
for (index, value) in super::super::codec::expect_array(raw, path)?
.iter()
.enumerate()
{
field_extension.push(path.with_index("extension", index, |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(value, path)?,
path,
)
})?);
}
}
let field_type = raw_type
.map(|value| {
path.with("type", |path| {
super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)
})
})
.transpose()?;
let field_dose = match raw_dose.suffix {
None => None,
Some(suffix) => Some(path.with("dose", |path| {
DosageDoseAndRateDose::from_json_parts(
suffix,
raw_dose.value,
raw_dose.element,
path,
)
})?),
};
let field_rate = match raw_rate.suffix {
None => None,
Some(suffix) => Some(path.with("rate", |path| {
DosageDoseAndRateRate::from_json_parts(
suffix,
raw_rate.value,
raw_rate.element,
path,
)
})?),
};
Ok(Self {
id: field_id,
extension: field_extension,
r#type: field_type,
dose: field_dose,
rate: field_rate,
})
}
}
impl serde::Serialize for DosageDoseAndRate {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
super::super::codec::Json::to_json(self)
.map_err(serde::ser::Error::custom)?
.serialize(serializer)
}
}
impl<'de> serde::Deserialize<'de> for DosageDoseAndRate {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let mut path = super::super::codec::Path::root("DosageDoseAndRate");
let object =
super::super::codec::expect_object(&value, &path).map_err(serde::de::Error::custom)?;
super::super::codec::Json::from_json(object, &mut path).map_err(serde::de::Error::custom)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DosageDoseAndRateDose {
Range(super::range::Range),
Quantity(super::quantity::Quantity),
}
impl DosageDoseAndRateDose {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<serde_json::Value>,
Option<serde_json::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Range(inner) => Ok((
"Range",
Some(serde_json::Value::Object(
super::super::codec::Json::to_json(inner)?,
)),
None,
)),
Self::Quantity(inner) => Ok((
"Quantity",
Some(serde_json::Value::Object(
super::super::codec::Json::to_json(inner)?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&serde_json::Value>,
element: Option<&serde_json::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(inner))
}
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(inner))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DosageDoseAndRateRate {
Ratio(super::ratio::Ratio),
Range(super::range::Range),
Quantity(super::quantity::Quantity),
}
impl DosageDoseAndRateRate {
pub fn to_json_parts(
&self,
) -> Result<
(
&'static str,
Option<serde_json::Value>,
Option<serde_json::Value>,
),
super::super::codec::EncodeError,
> {
match self {
Self::Ratio(inner) => Ok((
"Ratio",
Some(serde_json::Value::Object(
super::super::codec::Json::to_json(inner)?,
)),
None,
)),
Self::Range(inner) => Ok((
"Range",
Some(serde_json::Value::Object(
super::super::codec::Json::to_json(inner)?,
)),
None,
)),
Self::Quantity(inner) => Ok((
"Quantity",
Some(serde_json::Value::Object(
super::super::codec::Json::to_json(inner)?,
)),
None,
)),
}
}
pub fn from_json_parts(
suffix: &str,
value: Option<&serde_json::Value>,
element: Option<&serde_json::Value>,
path: &mut super::super::codec::Path,
) -> Result<Self, super::super::codec::DecodeError> {
match suffix {
"Ratio" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Ratio(inner))
}
"Range" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Range(inner))
}
"Quantity" => {
if element.is_some() {
return Err(path.error(super::super::codec::DecodeErrorKind::WrongType {
expected: "no underscore form for a complex type",
}));
}
let value = value.ok_or_else(|| {
path.error(super::super::codec::DecodeErrorKind::MissingProperty)
})?;
let inner = super::super::codec::Json::from_json(
super::super::codec::expect_object(
super::super::codec::expect_single(value, path)?,
path,
)?,
path,
)?;
Ok(Self::Quantity(inner))
}
_ => Err(path.error(super::super::codec::DecodeErrorKind::UnknownProperty)),
}
}
}