Skip to content

Commit

Permalink
Implement Encoder and Decoder for Box<T> (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvic authored Aug 9, 2024
1 parent f165668 commit a0ddedf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rustler/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ where
}
}

impl<T> Encoder for Box<T>
where
T: Encoder,
{
fn encode<'c>(&self, env: Env<'c>) -> Term<'c> {
self.as_ref().encode(env)
}
}

impl<'a, T> Decoder<'a> for Box<T>
where
T: Decoder<'a>,
{
fn decode(term: Term<'a>) -> NifResult<Self> {
term.decode().map(Box::new)
}
}

impl<T> Encoder for Option<T>
where
T: Encoder,
Expand Down

0 comments on commit a0ddedf

Please sign in to comment.