use crate::{
atom, value::Constructor, Array, Atom, BigInt, CString, Exception, Function, Module, Object,
Promise, String, Symbol, Value,
};
pub unsafe trait JsLifetime<'js> {
type Changed<'to>: 'to;
}
macro_rules! outlive_impls {
($($type:ident,)*) => {
$(
unsafe impl<'js> JsLifetime<'js> for $type<'js> {
type Changed<'to> = $type<'to>;
}
)*
};
}
outlive_impls! {
Value,
Symbol,
String,
CString,
Object,
Array,
BigInt,
Function,
Constructor,
Promise,
Exception,
Atom,
}
macro_rules! impl_outlive{
($($($ty:ident)::+$(<$($g:ident),+>)*),*$(,)?) => {
$(
unsafe impl<'js,$($($g,)*)*> JsLifetime<'js> for $($ty)::*$(<$($g,)*>)*
where
$($($g: JsLifetime<'js>,)*)*
{
type Changed<'to> = $($ty)::*$(<$($g::Changed<'to>,)*>)*;
}
)*
};
}
impl_outlive!(
u8,
u16,
u32,
u64,
usize,
u128,
i8,
i16,
i32,
i64,
isize,
i128,
char,
alloc::string::String,
alloc::vec::Vec<T>,
alloc::boxed::Box<T>,
core::option::Option<T>,
core::result::Result<T,E>,
core::cell::Cell<T>,
core::cell::RefCell<T>,
core::cell::UnsafeCell<T>,
alloc::collections::BTreeMap<K,V>,
alloc::collections::BTreeSet<K>,
alloc::collections::BinaryHeap<K>,
alloc::collections::LinkedList<T>,
alloc::collections::VecDeque<T>,
alloc::ffi::CString,
core::ops::Range<T>,
core::ops::RangeFrom<T>,
core::ops::RangeFull,
core::ops::RangeInclusive<T>,
core::ops::RangeTo<T>,
core::ops::RangeToInclusive<T>,
core::ops::Bound<T>,
core::ops::ControlFlow<B,C>,
alloc::rc::Rc<T>,
alloc::sync::Arc<T>,
atom::PredefinedAtom,
);
#[cfg(feature = "std")]
impl_outlive!(
std::backtrace::Backtrace,
std::collections::HashMap<K,V>,
std::collections::HashSet<K>,
std::ffi::OsString,
std::process::Child,
std::process::Command,
std::process::ExitCode,
std::process::ExitStatus,
std::process::Output,
std::process::Stdio,
std::path::PathBuf,
std::sync::Mutex<T>,
std::sync::RwLock<T>,
);
unsafe impl<'js, T: JsLifetime<'js>> JsLifetime<'js> for Module<'js, T> {
type Changed<'to> = Module<'to, T::Changed<'to>>;
}
unsafe impl<'js> JsLifetime<'js> for () {
type Changed<'to> = ();
}