Skip to content

Commit

Permalink
Serialization of optional values without Clone (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev authored Oct 7, 2022
1 parent 12362fc commit 035acab
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions proto/src/serializers/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ where
pub fn serialize<S, T>(value: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Clone + Default + Serialize,
T: Default + Serialize,
{
value.clone().unwrap_or_default().serialize(serializer)
match value {
Some(v) => v.serialize(serializer),
None => T::default().serialize(serializer),
}
}

0 comments on commit 035acab

Please sign in to comment.