diff --git a/protobuf-serde/src/lib.rs b/protobuf-serde/src/lib.rs index f02a4dd06..44ac302ba 100644 --- a/protobuf-serde/src/lib.rs +++ b/protobuf-serde/src/lib.rs @@ -15,7 +15,7 @@ pub fn serialize_singular_ptr_field(spf: &SingularPtrField, { match spf.as_ref() { Some(value) => value.serialize(serializer), - None => serializer.serialize_none() + None => serializer.serialize_none(), } } @@ -23,14 +23,6 @@ pub fn deserialize_singular_ptr_field<'de, D, T>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, T: Deserialize<'de> { - match Option::deserialize(deserializer) { - Ok(spf) => { - match spf { - Some(value) => Ok(SingularPtrField::some(value)), - None => Ok(SingularPtrField::none()) - } - } - Err(err) => Err(err) - } + Option::deserialize(deserializer).map(From::from) } diff --git a/protobuf/src/singular.rs b/protobuf/src/singular.rs index 139c39477..44681a16a 100644 --- a/protobuf/src/singular.rs +++ b/protobuf/src/singular.rs @@ -395,6 +395,18 @@ impl Default for SingularPtrField { } } +impl From> for SingularField { + fn from(o: Option) -> Self { + SingularField::from_option(o) + } +} + +impl From> for SingularPtrField { + fn from(o: Option) -> Self { + SingularPtrField::from_option(o) + } +} + impl Clone for SingularField { #[inline] fn clone(&self) -> SingularField {