Struct rquickjs_core::Persistent [−][src]
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);
NOTE: Be careful and ensure that no persistent links outlives the runtime.
Implementations
impl<T> Persistent<T>
[src]
pub fn save<'js>(ctx: Ctx<'js>, val: T) -> Persistent<T::Target> where
T: AsRef<Value<'js>> + Outlive<'static>,
[src]
T: AsRef<Value<'js>> + Outlive<'static>,
Save the value of an arbitrary type
pub fn restore<'js>(self, ctx: Ctx<'js>) -> Result<T::Target> where
T: Outlive<'js>,
T::Target: FromJs<'js>,
[src]
T: Outlive<'js>,
T::Target: FromJs<'js>,
Restore the value of an arbitrary type
Trait Implementations
impl<T> Clone for Persistent<T>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> Debug for Persistent<T>
[src]
impl<'t, T> Drop for Persistent<T>
[src]
impl<T> Eq for Persistent<T>
[src]
impl<'js, 't, T> FromJs<'js> for Persistent<T> where
T: Outlive<'js>,
T::Target: FromJs<'js> + IntoJs<'js>,
[src]
T: Outlive<'js>,
T::Target: FromJs<'js> + IntoJs<'js>,
impl<T> HasRefs for Persistent<T>
[src]
fn mark_refs(&self, marker: &RefsMarker)
[src]
impl<T> Hash for Persistent<T>
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'js, 't, T> IntoJs<'js> for Persistent<T> where
T: Outlive<'t>,
[src]
T: Outlive<'t>,
impl<T, S> PartialEq<Persistent<S>> for Persistent<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Persistent<T>
[src]
impl<T> !Send for Persistent<T>
[src]
impl<T> !Sync for Persistent<T>
[src]
impl<T> Unpin for Persistent<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for Persistent<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,