From 51618b1bfa2835fa74e3b8fb588737f231553b3a Mon Sep 17 00:00:00 2001 From: Mees Delzenne Date: Mon, 18 Nov 2024 16:55:58 +0100 Subject: [PATCH] Update some docs, fix a warning --- core/src/context/async.rs | 9 ++++----- core/src/js_lifetime.rs | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/src/context/async.rs b/core/src/context/async.rs index 8c31de20..4f9b071c 100644 --- a/core/src/context/async.rs +++ b/core/src/context/async.rs @@ -1,8 +1,5 @@ use super::{intrinsic, r#ref::ContextRef, ContextBuilder, Intrinsic}; -use crate::{ - context::ctx::RefCountHeader, markers::ParallelSend, qjs, runtime::AsyncRuntime, Ctx, Error, - Result, -}; +use crate::{markers::ParallelSend, qjs, runtime::AsyncRuntime, Ctx, Error, Result}; use std::{future::Future, mem, pin::Pin, ptr::NonNull}; mod future; @@ -111,7 +108,9 @@ impl Drop for Inner { None => { #[cfg(not(feature = "parallel"))] { - let p = unsafe { &mut *(self.ctx.as_ptr() as *mut RefCountHeader) }; + let p = unsafe { + &mut *(self.ctx.as_ptr() as *mut crate::context::ctx::RefCountHeader) + }; if p.ref_count <= 1 { // Lock was poisoned, this should only happen on a panic. // We should still free the context. diff --git a/core/src/js_lifetime.rs b/core/src/js_lifetime.rs index 06e9f2d4..3cf862a3 100644 --- a/core/src/js_lifetime.rs +++ b/core/src/js_lifetime.rs @@ -3,11 +3,11 @@ use crate::{ String, Symbol, Value, }; -/// The trait which signifies a type using the rquickjs `'js'` lifetime trick for maintaining safety around Javascript values. +/// The trait which signifies a type using the rquickjs `'js` lifetime trick for maintaining safety around Javascript values. /// /// # Safety /// -/// `JsLifetime<'js>` must be implemented for types which derive a `'js` lifetime from a Javascript +/// This trait can only be implemented for types which derive a `'js` lifetime from a Javascript /// value, directly or indirectly. /// /// All of the base Javascript types used in rquickjs like [`Value`] have a `'js` lifetime. If a @@ -22,7 +22,7 @@ use crate::{ /// unsound behavior. Correct implementions have the `'js` lifetime in `JsLifetime<'js>` be the /// same as the lifetime on the container, furthermore the associated type `Changed<'to>` is /// defined as the exact same type with the only difference being that the `'js` lifetime is now -/// `'to'. +/// `'to`. /// /// The following is a correct implementation of the [`JsLifetime`] trait. /// ``` @@ -34,9 +34,24 @@ use crate::{ /// } /// ``` /// +/// If a type does not have any lifetimes associated with it or all the lifetimes are `'static` +/// then if is always save to implement `JsLifetime`. +/// +/// See correct example for a static type below. +/// ``` +/// # use rquickjs::JsLifetime; +/// struct Bytes(Vec); +/// +/// unsafe impl<'js> JsLifetime<'js> for Bytes{ +/// type Changed<'to> = Bytes; +/// } +/// +/// ``` +/// +/// /// ## Incorrect examples /// -/// For example the following is unsound: +/// For example the following is unsound! /// ```no_run /// # use rquickjs::JsLifetime; /// struct Container<'js>(rquickjs::Object<'js>);