pub struct JsNumber(_);
Implementations
sourceimpl JsNumber
impl JsNumber
sourcepub fn int32(env: NapiEnv, value: i32) -> NapiResult<JsNumber>
pub fn int32(env: NapiEnv, value: i32) -> NapiResult<JsNumber>
This API is used to convert from the C int32_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
sourcepub fn uint32(env: NapiEnv, value: u32) -> NapiResult<JsNumber>
pub fn uint32(env: NapiEnv, value: u32) -> NapiResult<JsNumber>
This API is used to convert from the C uint32_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
sourcepub fn int64(env: NapiEnv, value: i64) -> NapiResult<JsNumber>
pub fn int64(env: NapiEnv, value: i64) -> NapiResult<JsNumber>
This API is used to convert from the C int64_t type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification. Note the complete range of int64_t cannot be represented with full precision in JavaScript. Integer values outside the range of Number.MIN_SAFE_INTEGER -(253 - 1) - Number.MAX_SAFE_INTEGER (253 - 1) will lose precision.
sourcepub fn double(env: NapiEnv, value: f64) -> NapiResult<JsNumber>
pub fn double(env: NapiEnv, value: f64) -> NapiResult<JsNumber>
This API is used to convert from the C double type to the JavaScript number type. The JavaScript number type is described in Section 6.1.6 of the ECMAScript Language Specification.
sourcepub fn get_value_int32(&self) -> NapiResult<i32>
pub fn get_value_int32(&self) -> NapiResult<i32>
If a non-number napi_value is passed in napi_number_expected. This API returns the C int32 primitive equivalent of the given JavaScript number. If the number exceeds the range of the 32 bit integer, then the result is truncated to the equivalent of the bottom 32 bits. This can result in a large positive number becoming a negative number if the value is > 231 - 1. Non-finite number values (NaN, +Infinity, or -Infinity) set the result to zero.
sourcepub fn get_value_uint32(&self) -> NapiResult<u32>
pub fn get_value_uint32(&self) -> NapiResult<u32>
If a non-number napi_value is passed in it returns napi_number_expected. This API returns the C primitive equivalent of the given napi_value as a uint32_t.
sourcepub fn get_value_int64(&self) -> NapiResult<i64>
pub fn get_value_int64(&self) -> NapiResult<i64>
If a non-number napi_value is passed in it returns napi_number_expected. This API returns the C int64 primitive equivalent of the given JavaScript number. number values outside the range of Number.MIN_SAFE_INTEGER -(253 - 1) - Number.MAX_SAFE_INTEGER (253 - 1) will lose precision. Non-finite number values (NaN, +Infinity, or -Infinity) set the result to zero.
sourcepub fn get_value_double(&self) -> NapiResult<f64>
pub fn get_value_double(&self) -> NapiResult<f64>
If a non-number napi_value is passed in it returns napi_number_expected. This API returns the C double primitive equivalent of the given JavaScript number.
Trait Implementations
sourceimpl NapiValueCheck for JsNumber
impl NapiValueCheck for JsNumber
fn check(&self) -> NapiResult<bool>
sourceimpl NapiValueT for JsNumber
impl NapiValueT for JsNumber
sourcefn from_raw(env: NapiEnv, raw: napi_value) -> JsNumber
fn from_raw(env: NapiEnv, raw: napi_value) -> JsNumber
construct value from raw pointer
sourcefn cast<T: NapiValueT>(&self) -> T
fn cast<T: NapiValueT>(&self) -> T
napi_value type cast
sourcefn cast_checked(&self) -> NapiResult<Self>
fn cast_checked(&self) -> NapiResult<Self>
Upcast to specified value
sourcefn kind(&self) -> NapiResult<NapiValuetype>
fn kind(&self) -> NapiResult<NapiValuetype>
Returns napi_ok if the API succeeded. Read more
sourcefn coerce_to_bool(&self) -> NapiResult<JsBoolean>
fn coerce_to_bool(&self) -> NapiResult<JsBoolean>
This API implements the abstract operation ToBoolean() as defined in Section 7.1.2 of the ECMAScript Language Specification. Read more
sourcefn coerce_coerce_to_number(&self) -> NapiResult<JsNumber>
fn coerce_coerce_to_number(&self) -> NapiResult<JsNumber>
This API implements the abstract operation ToNumber() as defined in Section 7.1.3 of the ECMAScript Language Specification. This function potentially runs JS code if the passed-in value is an object. Read more
sourcefn coerce_to_object(&self) -> NapiResult<JsObject>
fn coerce_to_object(&self) -> NapiResult<JsObject>
This API implements the abstract operation ToObject() as defined in Section 7.1.13 of the ECMAScript Language Specification. Read more
sourcefn coerce_to_string(&self) -> NapiResult<JsString>
fn coerce_to_string(&self) -> NapiResult<JsString>
This API implements the abstract operation ToString() as defined in Section 7.1.13 of the ECMAScript Language Specification. This function potentially runs JS code if the passed-in value is an object. Read more
sourcefn instance_of(&self, constructor: JsFunction) -> NapiResult<bool>
fn instance_of(&self, constructor: JsFunction) -> NapiResult<bool>
This API represents invoking the instanceof Operator on the object as defined in Section 12.10.4 of the ECMAScript Language Specification. Read more
sourcefn equals(&self, rhs: impl NapiValueT) -> NapiResult<bool>
fn equals(&self, rhs: impl NapiValueT) -> NapiResult<bool>
This API represents the invocation of the Strict Equality algorithm as defined in Section 7.2.14 of the ECMAScript Language Specification. Read more
sourcefn raw(&self) -> napi_value
fn raw(&self) -> napi_value
the raw-handle of current value
sourcefn null(&self) -> NapiResult<JsNull>
fn null(&self) -> NapiResult<JsNull>
get null singleton
sourcefn undefined(&self) -> NapiResult<JsUndefined>
fn undefined(&self) -> NapiResult<JsUndefined>
get undefined singleton
sourcefn global(&self) -> NapiResult<JsGlobal>
fn global(&self) -> NapiResult<JsGlobal>
get global singleton
sourcefn throw(&self) -> NapiResult<()>
fn throw(&self) -> NapiResult<()>
value is throwable
sourcefn define_properties<P>(&self, properties: P) -> NapiResult<()> where
P: AsRef<[NapiPropertyDescriptor]>,
fn define_properties<P>(&self, properties: P) -> NapiResult<()> where
P: AsRef<[NapiPropertyDescriptor]>,
This method allows the efficient definition of multiple properties on a given object. The properties are defined using property descriptors (see napi_property_descriptor). Given an array of such property descriptors, this API will set the properties on the object one at a time, as defined by DefineOwnProperty() (described in Section 9.1.6 of the ECMA-262 specification). Read more
sourcefn gc<Finalizer>(&mut self, finalizer: Finalizer) -> NapiResult<NapiRef> where
Finalizer: FnOnce(NapiEnv) -> NapiResult<()>,
fn gc<Finalizer>(&mut self, finalizer: Finalizer) -> NapiResult<NapiRef> where
Finalizer: FnOnce(NapiEnv) -> NapiResult<()>,
This is a hook which is fired when the value is gabage-collected. For napi >= 5, we use napi_add_finalizer, For napi < 5, we use napi_wrap. Read more
sourcefn finalizer<Finalizer>(&self, finalizer: Finalizer) -> NapiResult<NapiRef> where
Finalizer: FnOnce(NapiEnv) -> NapiResult<()>,
fn finalizer<Finalizer>(&self, finalizer: Finalizer) -> NapiResult<NapiRef> where
Finalizer: FnOnce(NapiEnv) -> NapiResult<()>,
Adds a napi_finalize callback which will be called when the JavaScript object in js_object is ready for garbage collection. This API is similar to napi_wrap() except that: Read more
sourcefn wrap<T, Finalizer>(
&mut self,
data: T,
finalizer: Finalizer
) -> NapiResult<NapiRef> where
Finalizer: FnOnce(NapiEnv, T) -> NapiResult<()>,
fn wrap<T, Finalizer>(
&mut self,
data: T,
finalizer: Finalizer
) -> NapiResult<NapiRef> where
Finalizer: FnOnce(NapiEnv, T) -> NapiResult<()>,
Wraps a native instance in a JavaScript object. The native instance can be retrieved later using napi_unwrap(). Read more
sourcefn unwrap<T>(&self) -> NapiResult<Option<&mut T>>
fn unwrap<T>(&self) -> NapiResult<Option<&mut T>>
Retrieves a native instance that was previously wrapped in a JavaScript object using napi_wrap(). Read more
sourcefn remove_wrap<T>(&mut self) -> NapiResult<T>
fn remove_wrap<T>(&mut self) -> NapiResult<T>
Retrieves a native instance that was previously wrapped in the JavaScript object js_object using napi_wrap() and removes the wrapping. If a finalize callback was associated with the wrapping, it will no longer be called when the JavaScript object becomes garbage-collected. Read more
sourcefn type_tag_object(&self, tag: &NapiTypeTag) -> NapiResult<()>
fn type_tag_object(&self, tag: &NapiTypeTag) -> NapiResult<()>
Associates the value of the type_tag pointer with the JavaScript object. napi_check_object_type_tag() can then be used to compare the tag that was attached to the object with one owned by the addon to ensure that the object has the right type. If the object already has an associated type tag, this API will return napi_invalid_arg. Read more
sourcefn check_object_type_tag(&self, tag: &NapiTypeTag) -> NapiResult<bool>
fn check_object_type_tag(&self, tag: &NapiTypeTag) -> NapiResult<bool>
Compares the pointer given as type_tag with any that can be found on js_object. If no tag is found on js_object or, if a tag is found but it does not match type_tag, then result is set to false. If a tag is found and it matches type_tag, then result is set to true. Read more
impl Copy for JsNumber
Auto Trait Implementations
impl RefUnwindSafe for JsNumber
impl !Send for JsNumber
impl !Sync for JsNumber
impl Unpin for JsNumber
impl UnwindSafe for JsNumber
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FromJsArgs for T where
T: NapiValueT,
impl<T> FromJsArgs for T where
T: NapiValueT,
fn from_js_args(args: JsArgs) -> Result<T, NapiStatus>
fn len() -> usize
sourceimpl<T> ToJsArgs for T where
T: NapiValueT,
impl<T> ToJsArgs for T where
T: NapiValueT,
fn to_js_args(self, env: NapiEnv) -> Result<JsArgs, NapiStatus>
fn len() -> usize
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more