Struct JsObject

Source
pub struct JsObject(/* private fields */);
Expand description

Pointer type for Js allocated object Consider this as a Box, but pointing into JS memory -1 is nil

Implementations§

Source§

impl JsObject

Source

pub fn weak(&self) -> JsObjectWeak

Get a weak reference to js memory No guarantees against js garbage collector

Source§

impl JsObject

Source

pub const NULL: Self

Source

pub const UNDEFINED: Self

Source

pub fn string(string: &str) -> JsObject

Allocate new javascript object with string type

Source

pub fn buffer(data: &[u8]) -> JsObject

Allocate new javascript object with Uint8Array type

Source

pub fn object() -> JsObject

Allocate new javascript object with object type. Like “var object = {}” in JS.

Source

pub fn to_string(&self, buf: &mut String)

Read JS object content to a given string Will panic if object is not a string Will not allocate memory if string is large enough, will use “String::reserve” otherwise

Source

pub fn to_byte_buffer(&self, buf: &mut Vec<u8>)

Read JS object content to a given bytes buffer Will panic if object is not a buffer Will use .resize() on “buf”, so if “buf” is large enough - no memory is going to be allocated here

Source

pub fn field(&self, field: &str) -> JsObject

Get a new JsObject from this object .field Will panic if self is not an object or map

Source

pub fn field_u32(&self, field: &str) -> u32

Get a value from this object .field Will panic if self is not an object or map

Source

pub fn have_field(&self, field: &str) -> bool

.field == undefined

Source

pub fn field_f32(&self, field: &str) -> f32

Get a value from this object .field Will panic if self is not an object or map

Source

pub fn set_field_f32(&self, field: &str, data: f32)

Set .field or [“field”] to given f32, like “object.field = data”; Will panic if self is not an object or map

Source

pub fn set_field_u32(&self, field: &str, data: u32)

Set .field or [“field”] to given u32, like “object.field = data”; Will panic if self is not an object or map

Source

pub fn set_field_string(&self, field: &str, data: &str)

Set .field or [“field”] to given string, like “object.field = data”; Will panic if self is not an object or map

Source

pub fn is_nil(&self) -> bool

Checks whether the JsObject handle is actually null

Source

pub fn is_undefined(&self) -> bool

Checks whether the JsObject handle is undefined

Trait Implementations§

Source§

impl Drop for JsObject

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.