Skip to content

Commit

Permalink
fmt and use separate impl block
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg committed Feb 18, 2023
1 parent f7dc455 commit 22e6d16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/shared_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ where

/// Create a shared pointer from an already-allocated object
/// Corresponds to constructor (3) of [std::shared\_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr)
///
///
/// The SharedPtr gains ownership of the pointer and will call std::default_delete on it when the refcount goes to zero.
/// The data will not be moved, so any pointers to this data elsewhere in the program continue to be valid
///
///
/// # Safety
///
///
/// Value must either be null or point to a valid instance of T
pub unsafe fn from_unmanaged(value: *mut T) -> Self {
let mut shared_ptr = MaybeUninit::<SharedPtr<T>>::uninit();
Expand Down
12 changes: 6 additions & 6 deletions src/unique_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ where
ty: PhantomData,
}
}
}

impl<T> UniquePtr<T>
where
T: UniquePtrTarget + SharedPtrTarget,
{
/// Convert this UniquePtr to a SharedPtr, analogous to constructor (13) for [std::shared\_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr)
pub fn to_shared(self) -> SharedPtr<T> where T: SharedPtrTarget {
pub fn to_shared(self) -> SharedPtr<T> {
unsafe { SharedPtr::from_unmanaged(self.into_raw()) }
}
}

impl<T> UniquePtr<T>
where T: UniquePtrTarget + SharedPtrTarget {
}

unsafe impl<T> Send for UniquePtr<T> where T: Send + UniquePtrTarget {}
unsafe impl<T> Sync for UniquePtr<T> where T: Sync + UniquePtrTarget {}

Expand Down Expand Up @@ -239,7 +240,6 @@ pub unsafe trait UniquePtrTarget {
unsafe fn __release(repr: MaybeUninit<*mut c_void>) -> *mut Self;
#[doc(hidden)]
unsafe fn __drop(repr: MaybeUninit<*mut c_void>);

}

extern "C" {
Expand Down

0 comments on commit 22e6d16

Please sign in to comment.