Skip to content

Commit 1fc3f7b

Browse files
authored
Merge pull request #14 from chmln/feat/add-option-conversion
feat: add conversion from `OwnedJsValue` for `Option`
2 parents 6c4629f + 44a6ed6 commit 1fc3f7b

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)