Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 87c059a

Browse files
feat: Implement Deserialize and IntoStatic for Box<T> (#107)
1 parent 7db3a0d commit 87c059a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

merde/examples/enums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
text: "Hello".into(),
1111
}),
1212
ExampleEvent::StringStuff(StringStuff("Some string".into())),
13-
ExampleEvent::Emergency(Emergency::NoPizzaLeft),
13+
ExampleEvent::Emergency(Box::new(Emergency::NoPizzaLeft)),
1414
];
1515

1616
for event in events {
@@ -30,7 +30,7 @@ enum ExampleEvent<'s> {
3030
MouseDown(MouseDown),
3131
TextInput(TextInput<'s>),
3232
StringStuff(StringStuff<'s>),
33-
Emergency(Emergency),
33+
Emergency(Box<Emergency>),
3434
}
3535

3636
merde::derive! {

merde_core/src/deserialize.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,16 @@ impl<'s> Deserialize<'s> for Cow<'s, str> {
409409
}
410410
}
411411

412+
impl<'s, T: Deserialize<'s>> Deserialize<'s> for Box<T> {
413+
async fn deserialize<D>(de: &mut D) -> Result<Self, D::Error<'s>>
414+
where
415+
D: Deserializer<'s> + ?Sized,
416+
{
417+
let value: T = de.t().await?;
418+
Ok(Box::new(value))
419+
}
420+
}
421+
412422
impl<'s, T: Deserialize<'s>> Deserialize<'s> for Option<T> {
413423
async fn deserialize<D>(de: &mut D) -> Result<Self, D::Error<'s>>
414424
where

merde_core/src/into_static.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ impl_into_static_passthru!(
9090
String, u128, u64, u32, u16, u8, i128, i64, i32, i16, i8, bool, char, usize, isize, f32, f64
9191
);
9292

93+
impl<T: IntoStatic> IntoStatic for Box<T> {
94+
type Output = Box<T::Output>;
95+
96+
fn into_static(self) -> Self::Output {
97+
Box::new((*self).into_static())
98+
}
99+
}
100+
93101
impl<T: IntoStatic> IntoStatic for Option<T> {
94102
type Output = Option<T::Output>;
95103

0 commit comments

Comments
 (0)