Skip to content

Commit

Permalink
Put constructor first
Browse files Browse the repository at this point in the history
Put the constructor method above the getters.

Code move only.
  • Loading branch information
tcharding committed Dec 29, 2024
1 parent c6ac14b commit 8d647dd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ impl<T> Ordered<T> {
/// The inner type is public so this function is never explicitly needed.
pub const fn new(inner: T) -> Self { Self(inner) }

/// Creates an `Ordered<T>` 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.
Expand All @@ -121,12 +127,6 @@ impl<T> Ordered<T> {
///
/// We also implement [`core::ops::Deref`] so this function is never explicitly needed.
pub fn into_inner(self) -> T { self.0 }

/// Creates an `Ordered<T>` 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<T: ArbitraryOrd> ArbitraryOrd for &T {
Expand Down

0 comments on commit 8d647dd

Please sign in to comment.