diff --git a/src/lib.rs b/src/lib.rs index b30205f..f40a1d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,6 +111,12 @@ impl Ordered { /// The inner type is public so this function is never explicitly needed. pub const fn new(inner: T) -> Self { Self(inner) } + /// Creates an `Ordered` from a reference. + /// + /// This allows: `let found = map.get(Ordered::from_ref(&a));` + #[allow(clippy::ptr_as_ptr)] + pub fn from_ref(value: &T) -> &Self { unsafe { &*(value as *const _ as *const Self) } } + /// Returns a reference to the inner object. /// /// We also implement [`core::borrow::Borrow`] so this function is never explicitly needed. @@ -120,12 +126,6 @@ impl Ordered { /// /// We also implement [`core::ops::Deref`] so this function is never explicitly needed. pub fn into_inner(self) -> T { self.0 } - - /// Creates an `Ordered` from a reference. - /// - /// This allows: `let found = map.get(Ordered::from_ref(&a));` - #[allow(clippy::ptr_as_ptr)] - pub fn from_ref(value: &T) -> &Self { unsafe { &*(value as *const _ as *const Self) } } } impl ArbitraryOrd for &T {