From 657bbb2bfcffada9a2e3b3e081df05084cc5ae4a Mon Sep 17 00:00:00 2001 From: dvic Date: Thu, 8 Aug 2024 23:29:01 +0200 Subject: [PATCH] Implement Encoder and Decoder for Box --- 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,