ptrait 0.1.0

A small crate providing traits for pointer-like types, such as references and smart pointers.
Documentation
use core::ptr;

use crate::{NonNullMutPtr, NonNullPtr, Ptr, PtrMut, RawMutPtr, RawPtr};

impl<T: ?Sized> Ptr for ptr::NonNull<T> {
    type Target = T;

    #[inline]
    fn as_ptr(&self) -> *const T {
        ptr::NonNull::as_ptr(*self)
    }

    #[inline]
    fn is_null(&self) -> bool {
        false
    }
}
impl<T: ?Sized> PtrMut for ptr::NonNull<T> {
    #[inline]
    fn as_mut_ptr(&mut self) -> *mut T {
        ptr::NonNull::as_ptr(*self)
    }
}

unsafe impl<T: ?Sized> NonNullPtr for ptr::NonNull<T> {}
unsafe impl<T: ?Sized> NonNullMutPtr for ptr::NonNull<T> {}

impl<T: ?Sized> RawPtr for ptr::NonNull<T> {}
impl<T: ?Sized> RawMutPtr for ptr::NonNull<T> {}

#[cfg(feature = "non_null_const")]
impl<T: ?Sized> Ptr for non_null_const::NonNullConst<T> {
    type Target = T;

    #[inline]
    fn as_ptr(&self) -> *const T {
        non_null_const::NonNullConst::as_ptr(*self)
    }

    #[inline]
    fn is_null(&self) -> bool {
        false
    }
}

#[cfg(feature = "non_null_const")]
unsafe impl<T: ?Sized> NonNullPtr for non_null_const::NonNullConst<T> {}

#[cfg(feature = "non_null_const")]
impl<T: ?Sized> RawPtr for non_null_const::NonNullConst<T> {}