Struct rquickjs_core::Persistent[][src]

pub struct Persistent<T> { /* fields omitted */ }

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]

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]

Restore the value of an arbitrary type

Trait Implementations

impl<T> Clone for Persistent<T>[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]

impl<T> HasRefs for Persistent<T>[src]

impl<T> Hash for Persistent<T>[src]

impl<'js, 't, T> IntoJs<'js> for Persistent<T> where
    T: Outlive<'t>, 
[src]

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]

impl<T> UnwindSafe for Persistent<T> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.