cachepadded: turn into pub newtype

This commit is contained in:
Janis 2025-07-05 14:21:15 +02:00
parent eee2f8995a
commit c9e69c3b06

View file

@ -146,9 +146,7 @@ use core::ops::{Deref, DerefMut};
)),
repr(align(64))
)]
pub struct CachePadded<T> {
value: T,
}
pub struct CachePadded<T>(pub T);
unsafe impl<T: Send> Send for CachePadded<T> {}
unsafe impl<T: Sync> Sync for CachePadded<T> {}
@ -164,7 +162,7 @@ impl<T> CachePadded<T> {
/// let padded_value = CachePadded::new(1);
/// ```
pub const fn new(t: T) -> CachePadded<T> {
CachePadded::<T> { value: t }
CachePadded::<T>(t)
}
/// Returns the inner value.
@ -179,7 +177,7 @@ impl<T> CachePadded<T> {
/// assert_eq!(value, 7);
/// ```
pub fn into_inner(self) -> T {
self.value
self.0
}
}
@ -187,20 +185,20 @@ impl<T> Deref for CachePadded<T> {
type Target = T;
fn deref(&self) -> &T {
&self.value
&self.0
}
}
impl<T> DerefMut for CachePadded<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.value
&mut self.0
}
}
impl<T: fmt::Debug> fmt::Debug for CachePadded<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CachePadded")
.field("value", &self.value)
.field("value", &self.0)
.finish()
}
}
@ -213,6 +211,6 @@ impl<T> From<T> for CachePadded<T> {
impl<T: fmt::Display> fmt::Display for CachePadded<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.value, f)
fmt::Display::fmt(&self.0, f)
}
}