Struct rquickjs_core::Persistent [−][src]
pub struct Persistent<T> { /* fields omitted */ }
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);
NOTE: Be careful and ensure that no persistent links outlives the runtime.
Implementations
Save the value of an arbitrary type
Trait Implementations
This is supported on crate feature
classes
only.Auto Trait Implementations
impl<T> !RefUnwindSafe for Persistent<T>
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
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.