Skip to content

Commit 44a6ed6

Browse files
committed
feat: add conversion from OwnedJsValue for Option
1 parent 6c4629f commit 44a6ed6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/value/value.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ impl TryFrom<OwnedJsValue> for num_bigint::BigInt {
564564
}
565565
}
566566

567+
impl<T: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for Option<T> {
568+
type Error = ValueError;
569+
570+
fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error> {
571+
if value.is_null() {
572+
return Ok(None);
573+
}
574+
Ok(Some(value.try_into()?))
575+
}
576+
}
577+
567578
impl<T: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for Vec<T> {
568579
type Error = ValueError;
569580

0 commit comments

Comments
 (0)