/// Creates an empty trait implementation for all common types. For generic collections, a bound is /// added that any type parameters implement the trait. /// /// This requires that `$trait` is a marker trait, as no associated types or methods will be /// implemented. /// /// These marker traits should also include a derive proc-macro in `turbo-tasks-macros` to allow /// easy implementation on structs or enums. /// /// This should eventually be replace by the `auto_traits`, once stabilized: /// https://doc.rust-lang.org/nightly/unstable-book/language-features/auto-traits.html macro_rules! impl_auto_marker_trait { ($trait:ident) => { $crate::marker_trait::impl_marker_trait!( $trait: i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize, f32, f64, char, bool, ); $crate::marker_trait::impl_marker_trait!( $trait: ::std::sync::atomic::AtomicI8, ::std::sync::atomic::AtomicU8, ::std::sync::atomic::AtomicI16, ::std::sync::atomic::AtomicU16, ::std::sync::atomic::AtomicI32, ::std::sync::atomic::AtomicU32, ::std::sync::atomic::AtomicI64, ::std::sync::atomic::AtomicU64, ::std::sync::atomic::AtomicBool, ::std::sync::atomic::AtomicUsize, ); $crate::marker_trait::impl_marker_trait!( $trait: (), str, ::std::string::String, ::std::time::Duration, ::anyhow::Error, ::turbo_rcstr::RcStr, ); $crate::marker_trait::impl_marker_trait!($trait: ::std::path::Path, ::std::path::PathBuf); $crate::marker_trait::impl_marker_trait!( $trait: ::serde_json::Value, ::serde_json::Map ); $crate::marker_trait::impl_marker_trait_fn_ptr!($trait: E D C B A Z Y X W V U T); $crate::marker_trait::impl_marker_trait_tuple!($trait: E D C B A Z Y X W V U T); unsafe impl $trait for ::std::option::Option {} unsafe impl $trait for ::std::vec::Vec {} unsafe impl $trait for ::smallvec::SmallVec<[T; N]> {} unsafe impl $trait for [T; N] {} unsafe impl $trait for [T] {} unsafe impl $trait for ::std::collections::HashSet {} unsafe impl $trait for ::auto_hash_map::AutoSet {} unsafe impl $trait for ::std::collections::BTreeSet {} unsafe impl $trait for ::indexmap::IndexSet {} unsafe impl $trait for ::std::collections::HashMap {} unsafe impl $trait for ::auto_hash_map::AutoMap {} unsafe impl $trait for ::std::collections::BTreeMap {} unsafe impl $trait for ::indexmap::IndexMap {} unsafe impl $trait for ::std::boxed::Box {} unsafe impl $trait for ::std::sync::Arc {} unsafe impl $trait for ::std::borrow::Cow<'_, B> {} unsafe impl $trait for ::std::result::Result {} unsafe impl $trait for ::std::sync::Mutex {} unsafe impl $trait for ::std::cell::RefCell {} unsafe impl $trait for ::std::marker::PhantomData {} unsafe impl $trait for ::either::Either {} unsafe impl $trait for $crate::TraitRef {} unsafe impl $trait for $crate::ReadRef where T: $crate::VcValueType, <::Read as $crate::VcRead>::Target: $trait {} unsafe impl $trait for $crate::State {} unsafe impl $trait for $crate::TransientState {} unsafe impl $trait for $crate::TransientValue {} unsafe impl $trait for $crate::TransientInstance {} unsafe impl $trait for &T {} unsafe impl $trait for &mut T {} } } /// Create a trivial marker trait implementation for trivial types with no generic parameters. /// /// Accepts a colon-separated `$trait` identifier followed by a comma-separated list of types to /// implement the `$trait` on. macro_rules! impl_marker_trait { ($trait:ident: $ty:ty $(,)?) => { unsafe impl $trait for $ty {} }; ($trait:ident: $ty:ty, $($tys:ty),+ $(,)?) => { $crate::marker_trait::impl_marker_trait!($trait: $ty); $crate::marker_trait::impl_marker_trait!($trait: $($tys),+); } } /// Create an implementation for every possible `fn` pointer type, regardless of the type of the /// arguments and return type. /// /// This is typically valid for marker traits as `fn` pointer types (not the `Fn` trait) do not /// contain any data, they are compile-time pointers to static code. macro_rules! impl_marker_trait_fn_ptr { ($trait:ident: $T:ident) => { $crate::marker_trait::impl_marker_trait_fn_ptr!(@impl $trait: $T); }; ($trait:ident: $T:ident $( $U:ident )+) => { $crate::marker_trait::impl_marker_trait_fn_ptr!($trait: $( $U )+); $crate::marker_trait::impl_marker_trait_fn_ptr!(@impl $trait: $T $( $U )+); }; (@impl $trait:ident: $( $T:ident )+) => { unsafe impl<$($T,)+ Return> $trait for fn($($T),+) -> Return {} }; } /// Create an implementation for every possible tuple where every element implements `$trait`. /// /// Must be passed a sequence of identifier to the tuple's generic parameters. This will only /// generate implementations up to the length of the passed in sequence. /// /// Based on stdlib's internal `tuple_impls!` macro. macro_rules! impl_marker_trait_tuple { ($trait:ident: $T:ident) => { $crate::marker_trait::impl_marker_trait_tuple!(@impl $trait: $T); }; ($trait:ident: $T:ident $( $U:ident )+) => { $crate::marker_trait::impl_marker_trait_tuple!($trait: $( $U )+); $crate::marker_trait::impl_marker_trait_tuple!(@impl $trait: $T $( $U )+); }; (@impl $trait:ident: $( $T:ident )+) => { unsafe impl<$($T: $trait),+> $trait for ($($T,)+) {} }; } pub(crate) use impl_auto_marker_trait; pub(crate) use impl_marker_trait; pub(crate) use impl_marker_trait_fn_ptr; pub(crate) use impl_marker_trait_tuple;