pub struct JsBigInt {
pub word_count: usize,
/* private fields */
}
Fields§
§word_count: usize
Implementations§
source§impl JsBigInt
impl JsBigInt
pub fn into_unknown(self) -> Result<JsUnknown>
pub fn coerce_to_number(self) -> Result<JsNumber>
pub fn coerce_to_string(self) -> Result<JsString>
pub fn coerce_to_object(self) -> Result<JsObject>
pub fn is_date(&self) -> Result<bool>
pub fn is_error(&self) -> Result<bool>
pub fn is_typedarray(&self) -> Result<bool>
pub fn is_dataview(&self) -> Result<bool>
pub fn is_array(&self) -> Result<bool>
pub fn is_buffer(&self) -> Result<bool>
pub fn instanceof<Constructor: NapiRaw>(
&self,
constructor: Constructor
) -> Result<bool>
source§impl JsBigInt
impl JsBigInt
sourcepub fn get_words(&mut self) -> Result<(bool, Vec<u64>)>
pub fn get_words(&mut self) -> Result<(bool, Vec<u64>)>
Examples found in repository?
src/js_values/bigint.rs (line 247)
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
pub fn get_i128(&mut self) -> Result<(i128, bool)> {
let (signed, words) = self.get_words()?;
let len = words.len();
let i128_words: [i64; 2] = [words[0] as _, words[1] as _];
let mut val = unsafe { ptr::read(i128_words.as_ptr() as *const i128) };
if signed {
val = -val;
}
Ok((val, len > 2))
}
pub fn get_u128(&mut self) -> Result<(bool, u128, bool)> {
let (signed, words) = self.get_words()?;
let len = words.len();
let u128_words: [u64; 2] = [words[0], words[1]];
let val = unsafe { ptr::read(u128_words.as_ptr() as *const u128) };
Ok((signed, val, len > 2))
}
pub fn get_i128(&mut self) -> Result<(i128, bool)>
sourcepub fn get_u128(&mut self) -> Result<(bool, u128, bool)>
pub fn get_u128(&mut self) -> Result<(bool, u128, bool)>
Examples found in repository?
src/js_values/de.rs (line 59)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
where
V: Visitor<'x>,
{
let js_value_type = type_of!(self.0.env, self.0.value)?;
match js_value_type {
ValueType::Null | ValueType::Undefined => visitor.visit_unit(),
ValueType::Boolean => {
let js_boolean = unsafe { JsBoolean::from_raw_unchecked(self.0.env, self.0.value) };
visitor.visit_bool(js_boolean.get_value()?)
}
ValueType::Number => {
let js_number: f64 =
unsafe { JsNumber::from_raw_unchecked(self.0.env, self.0.value).try_into()? };
if (js_number.trunc() - js_number).abs() < f64::EPSILON {
visitor.visit_i64(js_number as i64)
} else {
visitor.visit_f64(js_number)
}
}
ValueType::String => {
let js_string = unsafe { JsString::from_raw_unchecked(self.0.env, self.0.value) };
visitor.visit_str(js_string.into_utf8()?.as_str()?)
}
ValueType::Object => {
let js_object = unsafe { JsObject::from_raw_unchecked(self.0.env, self.0.value) };
if js_object.is_array()? {
let mut deserializer =
JsArrayAccess::new(&js_object, js_object.get_array_length_unchecked()?);
visitor.visit_seq(&mut deserializer)
} else if js_object.is_buffer()? {
visitor.visit_bytes(&JsBufferValue::from_raw(self.0.env, self.0.value)?)
} else {
let mut deserializer = JsObjectAccess::new(&js_object)?;
visitor.visit_map(&mut deserializer)
}
}
#[cfg(feature = "napi6")]
ValueType::BigInt => {
let mut js_bigint = unsafe { JsBigInt::from_raw(self.0.env, self.0.value)? };
let (signed, v, _loss) = js_bigint.get_u128()?;
if signed {
visitor.visit_i128(-(v as i128))
} else {
visitor.visit_u128(v)
}
}
ValueType::External | ValueType::Function | ValueType::Symbol => Err(Error::new(
Status::InvalidArg,
format!("typeof {:?} value could not be deserialized", js_value_type),
)),
ValueType::Unknown => unreachable!(),
}
}
Trait Implementations§
source§impl NapiValue for JsBigInt
impl NapiValue for JsBigInt
unsafe fn from_raw(env: napi_env, value: napi_value) -> Result<Self>
unsafe fn from_raw_unchecked(env: napi_env, value: napi_value) -> Self
source§impl TryFrom<JsBigInt> for i64
impl TryFrom<JsBigInt> for i64
The BigInt will be converted losslessly when the value is over what an int64 could hold.
source§impl TryFrom<JsBigInt> for u64
impl TryFrom<JsBigInt> for u64
The BigInt will be converted losslessly when the value is over what an uint64 could hold.
source§impl ValidateNapiValue for JsBigInt
impl ValidateNapiValue for JsBigInt
source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more