From a0ddedfcb298152e6aa4d887f3ac8770bb89178b Mon Sep 17 00:00:00 2001 From: Damir Vandic Date: Fri, 9 Aug 2024 13:42:19 +0200 Subject: [PATCH] Implement Encoder and Decoder for Box (#644) --- rustler/src/types/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rustler/src/types/mod.rs b/rustler/src/types/mod.rs index e43a1c7e..52c141cf 100644 --- a/rustler/src/types/mod.rs +++ b/rustler/src/types/mod.rs @@ -66,6 +66,24 @@ where } } +impl Encoder for Box +where + T: Encoder, +{ + fn encode<'c>(&self, env: Env<'c>) -> Term<'c> { + self.as_ref().encode(env) + } +} + +impl<'a, T> Decoder<'a> for Box +where + T: Decoder<'a>, +{ + fn decode(term: Term<'a>) -> NifResult { + term.decode().map(Box::new) + } +} + impl Encoder for Option where T: Encoder,