diff options
| author | Luca Casonato <hello@lcas.dev> | 2023-03-16 17:59:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-16 16:59:47 +0000 |
| commit | b99c431ac78810034ea57cc778bf57d627998aa9 (patch) | |
| tree | 4398efcd8d3757e42a5cd4bdcee4ed9533103f43 /serde_v8/serializable.rs | |
| parent | 1a3c2e2f1dc5add94b5b7ff4ba4c26df55c7a011 (diff) | |
feat(serde_v8): support BigInt serialization (#18225)
This commit enables serializing `v8::BigInt` to `num_bigint::BigInt`
in Rust.
Pre-requisite for sub upcoming feature work.
Diffstat (limited to 'serde_v8/serializable.rs')
| -rw-r--r-- | serde_v8/serializable.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/serde_v8/serializable.rs b/serde_v8/serializable.rs index 21c7bb752..b02aa0629 100644 --- a/serde_v8/serializable.rs +++ b/serde_v8/serializable.rs @@ -2,6 +2,7 @@ use std::any::TypeId; use std::mem::transmute_copy; +use crate::BigInt; use crate::ByteString; use crate::U16String; use crate::ZeroCopyBuf; @@ -65,6 +66,7 @@ pub enum Primitive { ZeroCopyBuf(ZeroCopyBuf), ByteString(ByteString), U16String(U16String), + BigInt(BigInt), } impl serde::Serialize for Primitive { @@ -89,6 +91,7 @@ impl serde::Serialize for Primitive { Self::ZeroCopyBuf(x) => x.serialize(s), Self::ByteString(x) => x.serialize(s), Self::U16String(x) => x.serialize(s), + Self::BigInt(x) => x.serialize(s), } } } @@ -137,6 +140,8 @@ impl<T: serde::Serialize + 'static> From<T> for SerializablePkg { Self::Primitive(Primitive::ByteString(tc(x))) } else if tid == TypeId::of::<U16String>() { Self::Primitive(Primitive::U16String(tc(x))) + } else if tid == TypeId::of::<BigInt>() { + Self::Primitive(Primitive::BigInt(tc(x))) } else { Self::Serializable(Box::new(x)) } |
