diff --git a/oden-js/src/conversion/from.rs b/oden-js/src/conversion/from.rs index d7a6acb4..d53f270c 100644 --- a/oden-js/src/conversion/from.rs +++ b/oden-js/src/conversion/from.rs @@ -104,3 +104,14 @@ impl TryFromValue for Value { Ok(value.dup(ctx)) } } + +impl TryFromValue for Option { + #[inline] + fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result { + if value.is_undefined() { + Ok(None) + } else { + Ok(Some(T::try_from_value(value, ctx)?)) + } + } +} diff --git a/oden-js/src/conversion/into.rs b/oden-js/src/conversion/into.rs index dbb5cf81..3dd5915f 100644 --- a/oden-js/src/conversion/into.rs +++ b/oden-js/src/conversion/into.rs @@ -128,3 +128,13 @@ impl TryIntoValue for T { self.into_value(ctx) } } + +impl TryIntoValue for Option { + #[inline] + fn try_into_value(self, ctx: &ContextRef) -> ValueResult { + match self { + None => Ok(ctx.undefined()), + Some(v) => v.try_into_value(ctx), + } + } +}