From 1f08348de81144a1d7858c7d9f36cc1de70e27c1 Mon Sep 17 00:00:00 2001 From: delskayn Date: Fri, 2 Jun 2023 10:07:42 +0200 Subject: [PATCH] Added some safety documentation --- core/src/context/async.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/context/async.rs b/core/src/context/async.rs index 56877be4..96f6a857 100644 --- a/core/src/context/async.rs +++ b/core/src/context/async.rs @@ -107,6 +107,17 @@ macro_rules! async_with{ let fut = Box::pin(async move { $($t)* }); + /// SAFETY: While rquickjs objects have a 'js lifetime attached to them, + /// they actually life much longer an the lifetime is just for checking + /// if they belong to the correct context. + /// By requiring that everything is moved into the closure outside + /// environments still can't life shorter than the closure. + /// This allows use to recast the future to a higher lifetime without problems. + /// Second, the future will always aquire a lock before running. The closure + /// enforces that everything moved into the future is send, but non of the + /// rquickjs objects are send so the future will never be send. + /// Since we aquire a lock before running the future and nothing can escape the closure + /// and future it is safe to recast the future as send. unsafe fn uplift<'a,'b,R>(f: std::pin::Pin + 'a>>) -> std::pin::Pin + 'b + Send>>{ std::mem::transmute(f) }