diff --git a/Cargo.toml b/Cargo.toml index e27ded5..924450c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blazemap" -version = "0.4.0" +version = "0.5.0" authors = ["Andrew Sonin "] categories = ["data-structures", "concurrency"] description = """ diff --git a/src/type_gen/key_wrapper_bounded.rs b/src/type_gen/key_wrapper_bounded.rs index 0402f21..374a836 100644 --- a/src/type_gen/key_wrapper_bounded.rs +++ b/src/type_gen/key_wrapper_bounded.rs @@ -115,11 +115,24 @@ macro_rules! key_wrapper_bounded_inner { #[cfg(not(loom))] impl $new_type { + #[doc = ::std::concat!("Creates a new instance of [`", ::std::stringify!($new_type), "`].")] #[inline] $vis fn new(value: $orig_type) -> Self { use $crate::traits::BlazeMapIdStatic; unsafe { ::new(Self::static_container(), value) } } + + #[doc = ::std::concat!( + "Returns the original key corresponding to the [`", + ::std::stringify!($new_type), + "`] instance." + )] + #[inline] + #[allow(dead_code)] + $vis fn key(self) -> &'static $orig_type { + let static_container = ::static_container(); + unsafe { static_container.key_by_offset_unchecked(self.0.into_offset()) } + } } impl $crate::prelude::BlazeMapId for $new_type diff --git a/src/type_info_containers/key_wrapper_bounded.rs b/src/type_info_containers/key_wrapper_bounded.rs index 172ae99..a252d61 100644 --- a/src/type_info_containers/key_wrapper_bounded.rs +++ b/src/type_info_containers/key_wrapper_bounded.rs @@ -92,6 +92,16 @@ impl StaticContainer { next_offset: AtomicUsize::new(0), } } + + #[inline] + #[doc(hidden)] + pub unsafe fn key_by_offset_unchecked(&self, offset: usize) -> &K { + #[cfg(not(loom))] + let result = (*self.offset_to_orig.get_unchecked(offset).get()).assume_init_ref(); + #[cfg(loom)] + let result = BorrowGuard(self.offset_to_orig.get(offset).unwrap().read().unwrap()); + result + } } impl WrapKey for StaticContainer @@ -206,10 +216,6 @@ impl Borrow for BorrowGuard<'_, K> { impl KeyByOffsetProvider for StaticContainer { #[inline] unsafe fn key_by_offset_unchecked(&self, offset: usize) -> impl Borrow { - #[cfg(not(loom))] - let result = (*self.offset_to_orig.get_unchecked(offset).get()).assume_init_ref(); - #[cfg(loom)] - let result = BorrowGuard(self.offset_to_orig.get(offset).unwrap().read().unwrap()); - result + StaticContainer::key_by_offset_unchecked(self, offset) } }