Remove change I am faaairly certain I did NOT add :O
I'm guessing it's some issue after a rebase or something...
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
#[macro_use]
|
||||
pub mod int_like;
|
||||
pub mod unique;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
use core::{fmt, ptr::NonNull};
|
||||
|
||||
/// A small wrapper around NonNull<T> that is Send + Sync, which is
|
||||
/// only correct if the pointer is never accessed from multiple
|
||||
/// locations across threads. Which is always, if the pointer is
|
||||
/// unique.
|
||||
pub struct Unique<T>(NonNull<T>);
|
||||
|
||||
impl<T> Copy for Unique<T> {}
|
||||
impl<T> Clone for Unique<T> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
unsafe impl<T> Send for Unique<T> {}
|
||||
unsafe impl<T> Sync for Unique<T> {}
|
||||
|
||||
impl<T> Unique<T> {
|
||||
pub fn new(ptr: *mut T) -> Self {
|
||||
Self(NonNull::new(ptr).unwrap())
|
||||
}
|
||||
pub unsafe fn new_unchecked(ptr: *mut T) -> Self {
|
||||
Self(NonNull::new_unchecked(ptr))
|
||||
}
|
||||
pub fn as_ptr(&self) -> *mut T {
|
||||
self.0.as_ptr()
|
||||
}
|
||||
}
|
||||
impl<T> fmt::Debug for Unique<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}", self.0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user