Skip to content

Commit

Permalink
Update some docs, fix a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
DelSkayn committed Nov 18, 2024
1 parent 4c17cd8 commit 51618b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
9 changes: 4 additions & 5 deletions core/src/context/async.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
Expand Down
23 changes: 19 additions & 4 deletions core/src/js_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
/// ```
Expand All @@ -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<u8>);
///
/// 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>);
Expand Down

0 comments on commit 51618b1

Please sign in to comment.