macro_rules! impl_thin_smart_ptr_common {
($Ty:ident) => {
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> $Ty<T, A> {
#[inline]
fn as_fat_ptr(&self) -> core::ptr::NonNull<T> {
unsafe { $crate::internal::thin_dst::as_fat::<T>(self.ptr) }
}
#[inline]
#[must_use]
pub fn as_ptr(&self) -> *const T {
self.as_fat_ptr().as_ptr().cast_const()
}
#[must_use]
#[inline]
pub fn into_pin(this: Self) -> core::pin::Pin<Self> {
unsafe { core::pin::Pin::new_unchecked(this) }
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> From<$Ty<T, A>> for core::pin::Pin<$Ty<T, A>> {
#[inline]
fn from(p: $Ty<T, A>) -> Self {
$Ty::into_pin(p)
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> core::ops::Deref for $Ty<T, A> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
unsafe { self.as_fat_ptr().as_ref() }
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> AsRef<T> for $Ty<T, A> {
#[inline]
fn as_ref(&self) -> &T {
self
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> core::borrow::Borrow<T> for $Ty<T, A> {
#[inline]
fn borrow(&self) -> &T {
self
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> core::fmt::Debug for $Ty<T, A>
where
T: core::fmt::Debug,
{
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(&**self, f)
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> core::fmt::Display for $Ty<T, A>
where
T: core::fmt::Display,
{
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Display::fmt(&**self, f)
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> PartialEq for $Ty<T, A>
where
T: PartialEq,
{
#[inline]
fn eq(&self, other: &Self) -> bool {
PartialEq::eq(&**self, &**other)
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> Eq for $Ty<T, A> where T: Eq {}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> PartialOrd for $Ty<T, A>
where
T: PartialOrd,
{
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
PartialOrd::partial_cmp(&**self, &**other)
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> Ord for $Ty<T, A>
where
T: Ord,
{
#[inline]
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
Ord::cmp(&**self, &**other)
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> core::hash::Hash for $Ty<T, A>
where
T: core::hash::Hash,
{
#[inline]
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
(**self).hash(state);
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> core::fmt::Pointer for $Ty<T, A> {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Pointer::fmt(&self.ptr.as_ptr(), f)
}
}
impl<T: ?Sized + ptr_meta::Pointee, A: allocator_api2::alloc::Allocator + Clone> Unpin for $Ty<T, A> {}
};
}
pub(crate) use impl_thin_smart_ptr_common;