Struct rquickjs_core::Persistent
source · pub struct Persistent<T> { /* private fields */ }
Expand description
The wrapper for JS values to keep it from GC
For example you can store JS functions for later use.
let func = ctx.with(|ctx| {
Persistent::save(&ctx, ctx.eval::<Function, _>("a => a + 1").unwrap())
});
let res: i32 = ctx.with(|ctx| {
let func = func.clone().restore(&ctx).unwrap();
func.call((2,)).unwrap()
});
assert_eq!(res, 3);
let res: i32 = ctx.with(|ctx| {
let func = func.restore(&ctx).unwrap();
func.call((0,)).unwrap()
});
assert_eq!(res, 1);
It is an error (Error::UnrelatedRuntime
) to restore the Persistent
in a
context who isn’t part of the original Runtime
.
NOTE: Be careful and ensure that no persistent links outlives the runtime, otherwise Runtime will abort the process when dropped.
Implementations§
source§impl<T> Persistent<T>
impl<T> Persistent<T>
Trait Implementations§
source§impl<T: Clone> Clone for Persistent<T>
impl<T: Clone> Clone for Persistent<T>
source§impl<T> Debug for Persistent<T>where
T: Debug,
impl<T> Debug for Persistent<T>where
T: Debug,
source§impl<'js, T, R> FromJs<'js> for Persistent<R>
impl<'js, T, R> FromJs<'js> for Persistent<R>
source§impl<T: Hash> Hash for Persistent<T>
impl<T: Hash> Hash for Persistent<T>
source§impl<'js, T> IntoJs<'js> for Persistent<T>
impl<'js, T> IntoJs<'js> for Persistent<T>
source§impl<T: PartialEq> PartialEq for Persistent<T>
impl<T: PartialEq> PartialEq for Persistent<T>
source§fn eq(&self, other: &Persistent<T>) -> bool
fn eq(&self, other: &Persistent<T>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl<T: Eq> Eq for Persistent<T>
impl<T> StructuralPartialEq for Persistent<T>
Auto Trait Implementations§
impl<T> Freeze for Persistent<T>where
T: Freeze,
impl<T> RefUnwindSafe for Persistent<T>where
T: RefUnwindSafe,
impl<T> !Send for Persistent<T>
impl<T> !Sync for Persistent<T>
impl<T> Unpin for Persistent<T>where
T: Unpin,
impl<T> UnwindSafe for Persistent<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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
Compare self to
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
The parameters requirements this value requires.
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>
Convert from a parameter value.
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>
Converts
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>
Converts
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