diff --git a/deptypes/Cargo.toml b/deptypes/Cargo.toml index 0b43e05..75f6772 100644 --- a/deptypes/Cargo.toml +++ b/deptypes/Cargo.toml @@ -25,4 +25,5 @@ default = ["std"] std = [] never = [] trusted_len = [] -nightly = ["never", "trusted_len"] +super_let = [] +nightly = ["never", "trusted_len", "super_let"] diff --git a/deptypes/src/guard.rs b/deptypes/src/guard.rs new file mode 100644 index 0000000..0ce48fc --- /dev/null +++ b/deptypes/src/guard.rs @@ -0,0 +1,20 @@ +pub use generativity::*; + +#[cfg(feature = "super_let")] +#[cfg_attr(docsrs, doc(cfg(feature = "super_let")))] +#[macro_export] +/// Create and return a [`generativity::Guard`] with a unique brand. +/// +/// This macro mirrors [`make_guard!`] but produces the guard directly instead +/// of binding it to a user-provided identifier. Because it relies on the +/// unstable `super_let` language feature, it is only available when the +/// crate's `"super_let"` feature is enabled (or through the `"nightly"` +/// feature, which enables `"super_let"`). +macro_rules! guard { + () => {{ + super let branded_place = unsafe { $crate::guard::Id::new() }; + #[allow(unused)] + let lifetime_brand = unsafe { $crate::guard::LifetimeBrand::new(&branded_place) }; + unsafe { $crate::guard::Guard::new(branded_place) } + }}; +} diff --git a/deptypes/src/lib.rs b/deptypes/src/lib.rs index f75f387..b20f8ca 100644 --- a/deptypes/src/lib.rs +++ b/deptypes/src/lib.rs @@ -2,6 +2,8 @@ #![cfg_attr(feature = "never", feature(never_type))] #![cfg_attr(feature = "trusted_len", feature(trusted_len))] +#![cfg_attr(feature = "super_let", feature(super_let))] +#![cfg_attr(docsrs, feature(doc_cfg))] #[cfg(feature = "std")] extern crate alloc; @@ -17,8 +19,13 @@ pub mod newtype; #[macro_use] pub mod zst; -pub use generativity as guard; -pub use generativity::make_guard as make_guard; +pub mod guard; +pub use crate::guard::make_guard as make_guard; + +#[cfg(feature = "super_let")] +#[cfg_attr(docsrs, doc(cfg(feature = "super_let")))] +#[doc(inline)] +pub use crate::guard::guard as g; #[macro_use] pub mod type_eq;