[oden-js] Convert Option<>
This commit is contained in:
parent
af12dccd5d
commit
c7903382a0
2 changed files with 21 additions and 0 deletions
|
|
@ -104,3 +104,14 @@ impl TryFromValue for Value {
|
|||
Ok(value.dup(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TryFromValue> TryFromValue for Option<T> {
|
||||
#[inline]
|
||||
fn try_from_value(value: &ValueRef, ctx: &ContextRef) -> Result<Self> {
|
||||
if value.is_undefined() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(T::try_from_value(value, ctx)?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,3 +128,13 @@ impl<T: Class> TryIntoValue for T {
|
|||
self.into_value(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TryIntoValue> TryIntoValue for Option<T> {
|
||||
#[inline]
|
||||
fn try_into_value(self, ctx: &ContextRef) -> ValueResult {
|
||||
match self {
|
||||
None => Ok(ctx.undefined()),
|
||||
Some(v) => v.try_into_value(ctx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue