Skip to content

Commit

Permalink
Implement Encoder and Decoder for Box<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
dvic committed Aug 8, 2024
1 parent f165668 commit 657bbb2
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 657bbb2

Please sign in to comment.