Struct rquickjs::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
Trait Implementations
sourceimpl<T> Clone for Persistent<T>
impl<T> Clone for Persistent<T>
sourcefn clone(&self) -> Persistent<T>
fn clone(&self) -> Persistent<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T> Debug for Persistent<T>
impl<T> Debug for Persistent<T>
sourceimpl<'t, T> Drop for Persistent<T>
impl<'t, T> Drop for Persistent<T>
sourceimpl<'js, 't, T> FromJs<'js> for Persistent<T> where
T: Outlive<'js>,
<T as Outlive<'js>>::Target: FromJs<'js>,
<T as Outlive<'js>>::Target: IntoJs<'js>,
impl<'js, 't, T> FromJs<'js> for Persistent<T> where
T: Outlive<'js>,
<T as Outlive<'js>>::Target: FromJs<'js>,
<T as Outlive<'js>>::Target: IntoJs<'js>,
sourceimpl<T> HasRefs for Persistent<T>
impl<T> HasRefs for Persistent<T>
fn mark_refs(&self, marker: &RefsMarker)
sourceimpl<T> Hash for Persistent<T>
impl<T> Hash for Persistent<T>
sourceimpl<'js, 't, T> IntoJs<'js> for Persistent<T> where
T: Outlive<'t>,
impl<'js, 't, T> IntoJs<'js> for Persistent<T> where
T: Outlive<'t>,
sourceimpl<T, S> PartialEq<Persistent<S>> for Persistent<T>
impl<T, S> PartialEq<Persistent<S>> for Persistent<T>
impl<T> Eq for Persistent<T>
impl<T> Send for Persistent<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe 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
sourceimpl<'js, T> AsProperty<'js, T> for T where
T: IntoJs<'js>,
impl<'js, T> AsProperty<'js, T> for T where
T: IntoJs<'js>,
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<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
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)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more