Skip to content

Commit

Permalink
Implement ValueDeserialize for Box<T>, Rc<T>, Arc<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Sep 14, 2024
1 parent a7eff10 commit f3bebf5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions merde_core/src/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,45 @@ impl<'s> ValueDeserialize<'s> for Map<'s> {
}
}

impl<'s, T> ValueDeserialize<'s> for Box<T>
where
T: ValueDeserialize<'s>,
{
fn from_value_ref<'val>(value: Option<&'val Value<'s>>) -> Result<Self, MerdeError> {
T::from_value_ref(value).map(Box::new)
}

fn from_value(value: Option<Value<'s>>) -> Result<Self, MerdeError> {
T::from_value(value).map(Box::new)
}
}

impl<'s, T> ValueDeserialize<'s> for std::rc::Rc<T>
where
T: ValueDeserialize<'s>,
{
fn from_value_ref<'val>(value: Option<&'val Value<'s>>) -> Result<Self, MerdeError> {
T::from_value_ref(value).map(std::rc::Rc::new)
}

fn from_value(value: Option<Value<'s>>) -> Result<Self, MerdeError> {
T::from_value(value).map(std::rc::Rc::new)
}
}

impl<'s, T> ValueDeserialize<'s> for std::sync::Arc<T>
where
T: ValueDeserialize<'s>,
{
fn from_value_ref<'val>(value: Option<&'val Value<'s>>) -> Result<Self, MerdeError> {
T::from_value_ref(value).map(std::sync::Arc::new)
}

fn from_value(value: Option<Value<'s>>) -> Result<Self, MerdeError> {
T::from_value(value).map(std::sync::Arc::new)
}
}

impl<'s, T1> ValueDeserialize<'s> for (T1,)
where
T1: ValueDeserialize<'s>,
Expand Down

0 comments on commit f3bebf5

Please sign in to comment.