pub struct ArrayBuffer<'js>(/* private fields */);Expand description
Rust representation of a JavaScript object of class ArrayBuffer.
Implementations§
Source§impl<'js> ArrayBuffer<'js>
impl<'js> ArrayBuffer<'js>
Sourcepub fn new<T: Copy>(ctx: Ctx<'js>, src: impl Into<Vec<T>>) -> Result<Self>
pub fn new<T: Copy>(ctx: Ctx<'js>, src: impl Into<Vec<T>>) -> Result<Self>
Create array buffer from vector data
Sourcepub fn new_copy<T: Copy>(ctx: Ctx<'js>, src: impl AsRef<[T]>) -> Result<Self>
pub fn new_copy<T: Copy>(ctx: Ctx<'js>, src: impl AsRef<[T]>) -> Result<Self>
Create array buffer from slice
Sourcepub fn from_source<S>(ctx: Ctx<'js>, src: S) -> Result<Self>where
S: ArrayBufferSource + ParallelSend + 'static,
pub fn from_source<S>(ctx: Ctx<'js>, src: S) -> Result<Self>where
S: ArrayBufferSource + ParallelSend + 'static,
Create an ArrayBuffer from a source that owns its backing bytes.
The source is moved into the buffer; JS has exclusive mutable access
until the buffer is collected, at which point the source is dropped.
Using this with a shared-immutable source (Arc<[u8]>, bytes::Bytes,
…) is unsound; use from_source_immutable for those.
Create a SharedArrayBuffer from a source that owns its backing bytes.
See from_source for ownership semantics.
Sourcepub fn from_source_immutable<S>(ctx: Ctx<'js>, src: S) -> Result<Self>where
S: ArrayBufferSource + ParallelSend + 'static,
pub fn from_source_immutable<S>(ctx: Ctx<'js>, src: S) -> Result<Self>where
S: ArrayBufferSource + ParallelSend + 'static,
Create an ArrayBuffer that JS sees as immutable, backed by a
possibly shared-immutable source.
JS writes throw, so it is sound for the caller to keep holding
shared-immutable references to the backing store (Arc<[u8]>,
bytes::Bytes, …).
Sourcepub unsafe fn as_bytes(&self) -> Option<&[u8]>
pub unsafe fn as_bytes(&self) -> Option<&[u8]>
Returns the underlying bytes of the buffer,
Returns None if the array is detached.
§Safety
The returned slice aliases memory owned by the JS engine. The caller must not run any JavaScript for as long as the slice is alive, since JS can write into, detach, or (for a resizable buffer) reallocate the backing store, invalidating the slice.
Sourcepub unsafe fn as_slice<T: TypedArrayItem>(
&self,
) -> StdResult<&[T], AsSliceError>
pub unsafe fn as_slice<T: TypedArrayItem>( &self, ) -> StdResult<&[T], AsSliceError>
Returns a slice if the buffer underlying buffer is properly aligned for the type and the buffer is not detached.
§Safety
The returned slice aliases memory owned by the JS engine. The caller must not run any JavaScript for as long as the slice is alive, since JS can write into, detach, or (for a resizable buffer) reallocate the backing store, invalidating the slice.
Sourcepub fn into_value(self) -> Value<'js>
pub fn into_value(self) -> Value<'js>
Convert into value
Sourcepub fn from_value(value: Value<'js>) -> Option<Self>
pub fn from_value(value: Value<'js>) -> Option<Self>
Convert from value
Sourcepub fn into_object(self) -> Object<'js>
pub fn into_object(self) -> Object<'js>
Convert into an object
Sourcepub fn from_object(object: Object<'js>) -> Option<Self>
pub fn from_object(object: Object<'js>) -> Option<Self>
Convert from an object
Sourcepub fn as_raw(&self) -> Option<NonNull<[u8]>>
pub fn as_raw(&self) -> Option<NonNull<[u8]>>
Returns a pointer to the underlying bytes of the buffer,
The returned pointer is only guaranteed valid until the next time JavaScript runs: JS can write through it, detach the buffer, or, for a resizable buffer, reallocate the backing store and free this pointer. Treat the pointer as invalidated after any call back into the engine.
Returns None if the buffer was already detached.
Methods from Deref<Target = Object<'js>>§
Sourcepub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<()>where
K: IntoAtom<'js>,
V: AsProperty<'js, P>,
pub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<()>where
K: IntoAtom<'js>,
V: AsProperty<'js, P>,
Define a property of an object
// Define readonly property without value
obj.prop("no_val", ()).unwrap();
// Define readonly property with value
obj.prop("ro_str", "Some const text").unwrap();
// Define readonly property with value and make it to be writable
obj.prop("ro_str2", Property::from("Some const text").writable()).unwrap();
// Define readonly property using getter and make it to be enumerable
obj.prop("ro_str_get", Accessor::from(|| "Some readable text").enumerable()).unwrap();
// Define readonly property using getter and setter
obj.prop("ro_str_get_set",
Accessor::from(|| "Some text")
.set(|new_val: String| { /* do something */ })
).unwrap();Sourcepub fn contains_key<K>(&self, k: K) -> Result<bool>where
K: IntoAtom<'js>,
pub fn contains_key<K>(&self, k: K) -> Result<bool>where
K: IntoAtom<'js>,
check whether the object contains a certain key.
Sourcepub fn set<K: IntoAtom<'js>, V: IntoJs<'js>>(
&self,
key: K,
value: V,
) -> Result<()>
pub fn set<K: IntoAtom<'js>, V: IntoJs<'js>>( &self, key: K, value: V, ) -> Result<()>
Set a member of an object to a certain value
Sourcepub fn keys<K: FromAtom<'js>>(&self) -> ObjectKeysIter<'js, K> ⓘ
pub fn keys<K: FromAtom<'js>>(&self) -> ObjectKeysIter<'js, K> ⓘ
Get own string enumerable property names of an object
Sourcepub fn own_keys<K: FromAtom<'js>>(
&self,
filter: Filter,
) -> ObjectKeysIter<'js, K> ⓘ
pub fn own_keys<K: FromAtom<'js>>( &self, filter: Filter, ) -> ObjectKeysIter<'js, K> ⓘ
Get own property names of an object
Sourcepub fn props<K: FromAtom<'js>, V: FromJs<'js>>(&self) -> ObjectIter<'js, K, V> ⓘ
pub fn props<K: FromAtom<'js>, V: FromJs<'js>>(&self) -> ObjectIter<'js, K, V> ⓘ
Get own string enumerable properties of an object
Sourcepub fn own_props<K: FromAtom<'js>, V: FromJs<'js>>(
&self,
filter: Filter,
) -> ObjectIter<'js, K, V> ⓘ
pub fn own_props<K: FromAtom<'js>, V: FromJs<'js>>( &self, filter: Filter, ) -> ObjectIter<'js, K, V> ⓘ
Get own properties of an object
Sourcepub fn values<K: FromAtom<'js>>(&self) -> ObjectValuesIter<'js, K> ⓘ
pub fn values<K: FromAtom<'js>>(&self) -> ObjectValuesIter<'js, K> ⓘ
Get own string enumerable property values of an object
Sourcepub fn own_values<K: FromAtom<'js>>(
&self,
filter: Filter,
) -> ObjectValuesIter<'js, K> ⓘ
pub fn own_values<K: FromAtom<'js>>( &self, filter: Filter, ) -> ObjectValuesIter<'js, K> ⓘ
Get own property values of an object
Sourcepub fn get_prototype(&self) -> Option<Object<'js>>
pub fn get_prototype(&self) -> Option<Object<'js>>
Get an object prototype
Objects can have no prototype, in this case this function will return null.
Sourcepub fn set_prototype(&self, proto: Option<&Object<'js>>) -> Result<()>
pub fn set_prototype(&self, proto: Option<&Object<'js>>) -> Result<()>
Set an object prototype
If called with None the function will set the prototype of the object to null.
This function will error if setting the prototype causes a cycle in the prototype chain.
Sourcepub fn is_instance_of(&self, class: impl AsRef<Value<'js>>) -> bool
pub fn is_instance_of(&self, class: impl AsRef<Value<'js>>) -> bool
Check instance of object
Sourcepub fn is_array_buffer(&self) -> bool
pub fn is_array_buffer(&self) -> bool
Returns whether the object is an instance of ArrayBuffer.
Sourcepub unsafe fn ref_array_buffer(&self) -> &ArrayBuffer<'_>
pub unsafe fn ref_array_buffer(&self) -> &ArrayBuffer<'_>
Sourcepub fn as_array_buffer(&self) -> Option<&ArrayBuffer<'_>>
pub fn as_array_buffer(&self) -> Option<&ArrayBuffer<'_>>
Turn the object into an array buffer if the object is an instance of ArrayBuffer.
pub fn is_typed_array<T: TypedArrayItem>(&self) -> bool
Sourcepub unsafe fn ref_typed_array<'a, T: TypedArrayItem>(
&'a self,
) -> &'a TypedArray<'js, T>
pub unsafe fn ref_typed_array<'a, T: TypedArrayItem>( &'a self, ) -> &'a TypedArray<'js, T>
pub fn as_typed_array<T: TypedArrayItem>(&self) -> Option<&TypedArray<'js, T>>
Sourcepub fn instance_of<C: JsClass<'js>>(&self) -> bool
pub fn instance_of<C: JsClass<'js>>(&self) -> bool
Returns if the object is of a certain Rust class.
Sourcepub fn into_class<C: JsClass<'js>>(&self) -> Result<Class<'js, C>, &Self>
pub fn into_class<C: JsClass<'js>>(&self) -> Result<Class<'js, C>, &Self>
Turn the object into the class if it is an instance of that class.
Methods from Deref<Target = Value<'js>>§
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Returns if the value is the JavaScript undefined value.
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Check if the value is a function
Sourcepub fn is_constructor(&self) -> bool
pub fn is_constructor(&self) -> bool
Check if the value is a constructor function
Sourcepub fn is_promise(&self) -> bool
pub fn is_promise(&self) -> bool
Check if the value is a promise.
Sourcepub fn is_exception(&self) -> bool
pub fn is_exception(&self) -> bool
Check if the value is an exception
Sourcepub fn is_uncatchable_error(&self) -> bool
pub fn is_uncatchable_error(&self) -> bool
Check if the value is an uncatchable error (e.g. from an interrupt handler)
Sourcepub fn is_big_int(&self) -> bool
pub fn is_big_int(&self) -> bool
Check if the value is a BigInt
Sourcepub unsafe fn ref_string(&self) -> &String<'js>
pub unsafe fn ref_string(&self) -> &String<'js>
Sourcepub unsafe fn ref_symbol(&self) -> &Symbol<'js>
pub unsafe fn ref_symbol(&self) -> &Symbol<'js>
Sourcepub unsafe fn ref_object(&self) -> &Object<'js>
pub unsafe fn ref_object(&self) -> &Object<'js>
Sourcepub unsafe fn ref_function(&self) -> &Function<'js>
pub unsafe fn ref_function(&self) -> &Function<'js>
Sourcepub fn as_function(&self) -> Option<&Function<'js>>
pub fn as_function(&self) -> Option<&Function<'js>>
Try reinterpret as Function
Sourcepub unsafe fn ref_constructor(&self) -> &Constructor<'js>
pub unsafe fn ref_constructor(&self) -> &Constructor<'js>
Interpret as Constructor
§Safety
You should be sure that the value already is of required type before to do it.
Sourcepub fn as_constructor(&self) -> Option<&Constructor<'js>>
pub fn as_constructor(&self) -> Option<&Constructor<'js>>
Try reinterpret as Constructor
Sourcepub unsafe fn ref_promise(&self) -> &Promise<'js>
pub unsafe fn ref_promise(&self) -> &Promise<'js>
Sourcepub fn as_promise(&self) -> Option<&Promise<'js>>
pub fn as_promise(&self) -> Option<&Promise<'js>>
Try reinterpret as Promise
Sourcepub unsafe fn ref_exception(&self) -> &Exception<'js>
pub unsafe fn ref_exception(&self) -> &Exception<'js>
Sourcepub fn as_exception(&self) -> Option<&Exception<'js>>
pub fn as_exception(&self) -> Option<&Exception<'js>>
Try reinterpret as Exception
Sourcepub unsafe fn ref_big_int(&self) -> &BigInt<'js>
pub unsafe fn ref_big_int(&self) -> &BigInt<'js>
Sourcepub fn as_big_int(&self) -> Option<&BigInt<'js>>
pub fn as_big_int(&self) -> Option<&BigInt<'js>>
Try reinterpret as BigInt
Trait Implementations§
Source§impl<'js> AsRef<Object<'js>> for ArrayBuffer<'js>
impl<'js> AsRef<Object<'js>> for ArrayBuffer<'js>
Source§impl<'js> AsRef<Value<'js>> for ArrayBuffer<'js>
impl<'js> AsRef<Value<'js>> for ArrayBuffer<'js>
Source§impl<'js> Clone for ArrayBuffer<'js>
impl<'js> Clone for ArrayBuffer<'js>
Source§fn clone(&self) -> ArrayBuffer<'js>
fn clone(&self) -> ArrayBuffer<'js>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'js> Debug for ArrayBuffer<'js>
impl<'js> Debug for ArrayBuffer<'js>
Source§impl<'js> Deref for ArrayBuffer<'js>
impl<'js> Deref for ArrayBuffer<'js>
impl<'js> Eq for ArrayBuffer<'js>
Source§impl<'js> FromJs<'js> for ArrayBuffer<'js>
impl<'js> FromJs<'js> for ArrayBuffer<'js>
Source§impl<'js> Hash for ArrayBuffer<'js>
impl<'js> Hash for ArrayBuffer<'js>
Source§impl<'js> IntoJs<'js> for ArrayBuffer<'js>
impl<'js> IntoJs<'js> for ArrayBuffer<'js>
Source§impl<'js> JsLifetime<'js> for ArrayBuffer<'js>
impl<'js> JsLifetime<'js> for ArrayBuffer<'js>
Source§type Changed<'to> = ArrayBuffer<'to>
type Changed<'to> = ArrayBuffer<'to>
Self but with another lifetime 'tSource§impl<'js> PartialEq for ArrayBuffer<'js>
impl<'js> PartialEq for ArrayBuffer<'js>
impl<'js> StructuralPartialEq for ArrayBuffer<'js>
Source§impl<'js, T> TryFrom<ArrayBuffer<'js>> for TypedArray<'js, T>where
T: TypedArrayItem,
impl<'js, T> TryFrom<ArrayBuffer<'js>> for TypedArray<'js, T>where
T: TypedArrayItem,
Source§impl<'js, T> TryFrom<TypedArray<'js, T>> for ArrayBuffer<'js>
impl<'js, T> TryFrom<TypedArray<'js, T>> for ArrayBuffer<'js>
Auto Trait Implementations§
impl<'js> !Send for ArrayBuffer<'js>
impl<'js> !Sync for ArrayBuffer<'js>
impl<'js> !UnwindSafe for ArrayBuffer<'js>
impl<'js> Freeze for ArrayBuffer<'js>
impl<'js> RefUnwindSafe for ArrayBuffer<'js>
impl<'js> Unpin for ArrayBuffer<'js>
impl<'js> UnsafeUnpin for ArrayBuffer<'js>
Blanket Implementations§
Source§impl<'js, T> AsProperty<'js, T> for Twhere
T: IntoJs<'js>,
impl<'js, T> AsProperty<'js, T> for Twhere
T: IntoJs<'js>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<'js, T> FromParam<'js> for Twhere
T: FromJs<'js>,
impl<'js, T> FromParam<'js> for Twhere
T: FromJs<'js>,
Source§fn param_requirement() -> ParamRequirement
fn param_requirement() -> ParamRequirement
Source§fn from_param<'a>(params: &mut ParamsAccessor<'a, 'js>) -> Result<T, Error>
fn from_param<'a>(params: &mut ParamsAccessor<'a, 'js>) -> Result<T, Error>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more