Struct rquickjs::ArrayBuffer
source · pub struct ArrayBuffer<'js>(/* private fields */);
array-buffer
only.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>(
ctx: Ctx<'js>,
src: impl Into<Vec<T>>
) -> Result<ArrayBuffer<'js>, Error>where
T: Copy,
pub fn new<T>(
ctx: Ctx<'js>,
src: impl Into<Vec<T>>
) -> Result<ArrayBuffer<'js>, Error>where
T: Copy,
Create array buffer from vector data
sourcepub fn new_copy<T>(
ctx: Ctx<'js>,
src: impl AsRef<[T]>
) -> Result<ArrayBuffer<'js>, Error>where
T: Copy,
pub fn new_copy<T>(
ctx: Ctx<'js>,
src: impl AsRef<[T]>
) -> Result<ArrayBuffer<'js>, Error>where
T: Copy,
Create array buffer from slice
sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
Returns the underlying bytes of the buffer,
Returns None
if the array is detached.
sourcepub fn as_slice<T>(&self) -> Result<&[T], AsSliceError>where
T: TypedArrayItem,
pub fn as_slice<T>(&self) -> Result<&[T], AsSliceError>where
T: TypedArrayItem,
Returns a slice if the buffer underlying buffer is properly aligned for the type and the buffer is not detached.
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<ArrayBuffer<'js>>
pub fn from_value(value: Value<'js>) -> Option<ArrayBuffer<'js>>
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<ArrayBuffer<'js>>
pub fn from_object(object: Object<'js>) -> Option<ArrayBuffer<'js>>
Convert from an object
Methods from Deref<Target = Object<'js>>§
sourcepub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<(), Error>where
K: IntoAtom<'js>,
V: AsProperty<'js, P>,
Available on crate feature properties
only.
pub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<(), Error>where
K: IntoAtom<'js>,
V: AsProperty<'js, P>,
properties
only.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, Error>where
K: IntoAtom<'js>,
pub fn contains_key<K>(&self, k: K) -> Result<bool, Error>where
K: IntoAtom<'js>,
check whether the object contains a certain key.
sourcepub fn set<K, V>(&self, key: K, value: V) -> Result<(), Error>
pub fn set<K, V>(&self, key: K, value: V) -> Result<(), Error>
Set a member of an object to a certain value
sourcepub fn remove<K>(&self, key: K) -> Result<(), Error>where
K: IntoAtom<'js>,
pub fn remove<K>(&self, key: K) -> Result<(), Error>where
K: IntoAtom<'js>,
Remove a member of an object
sourcepub fn keys<K>(&self) -> ObjectKeysIter<'js, K> ⓘwhere
K: FromAtom<'js>,
pub fn keys<K>(&self) -> ObjectKeysIter<'js, K> ⓘwhere
K: FromAtom<'js>,
Get own string enumerable property names of an object
sourcepub fn own_keys<K>(&self, filter: Filter) -> ObjectKeysIter<'js, K> ⓘwhere
K: FromAtom<'js>,
pub fn own_keys<K>(&self, filter: Filter) -> ObjectKeysIter<'js, K> ⓘwhere
K: FromAtom<'js>,
Get own property names of an object
sourcepub fn props<K, V>(&self) -> ObjectIter<'js, K, V> ⓘ
pub fn props<K, V>(&self) -> ObjectIter<'js, K, V> ⓘ
Get own string enumerable properties of an object
sourcepub fn own_props<K, V>(&self, filter: Filter) -> ObjectIter<'js, K, V> ⓘ
pub fn own_props<K, V>(&self, filter: Filter) -> ObjectIter<'js, K, V> ⓘ
Get own properties of an object
sourcepub fn values<K>(&self) -> ObjectValuesIter<'js, K> ⓘwhere
K: FromAtom<'js>,
pub fn values<K>(&self) -> ObjectValuesIter<'js, K> ⓘwhere
K: FromAtom<'js>,
Get own string enumerable property values of an object
sourcepub fn own_values<K>(&self, filter: Filter) -> ObjectValuesIter<'js, K> ⓘwhere
K: FromAtom<'js>,
pub fn own_values<K>(&self, filter: Filter) -> ObjectValuesIter<'js, K> ⓘwhere
K: FromAtom<'js>,
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<(), Error>
pub fn set_prototype(&self, proto: Option<&Object<'js>>) -> Result<(), Error>
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>(&self) -> boolwhere
T: TypedArrayItem,
sourcepub unsafe fn ref_typed_array<'a, T>(&'a self) -> &'a TypedArray<'a, T>where
T: TypedArrayItem,
pub unsafe fn ref_typed_array<'a, T>(&'a self) -> &'a TypedArray<'a, T>where
T: TypedArrayItem,
pub fn as_typed_array<T>(&self) -> Option<&TypedArray<'_, T>>where
T: TypedArrayItem,
sourcepub fn instance_of<C>(&self) -> boolwhere
C: JsClass<'js>,
pub fn instance_of<C>(&self) -> boolwhere
C: JsClass<'js>,
Returns if the object is of a certain Rust 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 get<T>(&self) -> Result<T, Error>where
T: FromJs<'js>,
pub fn get<T>(&self) -> Result<T, Error>where
T: FromJs<'js>,
Convert from value to specified type
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, T> AsRef<[T]> for ArrayBuffer<'js>where
T: TypedArrayItem,
impl<'js, T> AsRef<[T]> for ArrayBuffer<'js>where
T: TypedArrayItem,
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 · 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>
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> Outlive<'js> for ArrayBuffer<'js>
impl<'js> Outlive<'js> for ArrayBuffer<'js>
§type Target<'to> = ArrayBuffer<'to>
type Target<'to> = ArrayBuffer<'to>
Self
but with another lifetime 't
source§impl<'js> PartialEq for ArrayBuffer<'js>
impl<'js> PartialEq for ArrayBuffer<'js>
source§fn eq(&self, other: &ArrayBuffer<'js>) -> bool
fn eq(&self, other: &ArrayBuffer<'js>) -> bool
self
and other
values to be equal, and is used
by ==
.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§fn try_from(ab: ArrayBuffer<'js>) -> Result<TypedArray<'js, T>, Error>
fn try_from(ab: ArrayBuffer<'js>) -> Result<TypedArray<'js, T>, Error>
source§impl<'js, T> TryFrom<TypedArray<'js, T>> for ArrayBuffer<'js>
impl<'js, T> TryFrom<TypedArray<'js, T>> for ArrayBuffer<'js>
source§fn try_from(ta: TypedArray<'js, T>) -> Result<ArrayBuffer<'js>, Error>
fn try_from(ta: TypedArray<'js, T>) -> Result<ArrayBuffer<'js>, Error>
impl<'js> Eq for ArrayBuffer<'js>
impl<'js> StructuralPartialEq for ArrayBuffer<'js>
Auto Trait Implementations§
impl<'js> Freeze for ArrayBuffer<'js>
impl<'js> RefUnwindSafe for ArrayBuffer<'js>
impl<'js> !Send for ArrayBuffer<'js>
impl<'js> !Sync for ArrayBuffer<'js>
impl<'js> Unpin for ArrayBuffer<'js>
impl<'js> !UnwindSafe 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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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