use core::{cmp::Ordering, fmt, hash, marker::PhantomData, ptr::NonNull};
use crate::access::ReadWrite;
mod macros;
mod operations;
#[cfg(test)]
mod tests;
#[cfg(feature = "unstable")]
mod unstable;
#[cfg(feature = "very_unstable")]
mod very_unstable;
#[must_use]
#[repr(transparent)]
pub struct VolatilePtr<'a, T, A = ReadWrite>
where
T: ?Sized,
{
pointer: NonNull<T>,
reference: PhantomData<&'a T>,
access: PhantomData<A>,
}
impl<'a, T, A> Copy for VolatilePtr<'a, T, A> where T: ?Sized {}
impl<T, A> Clone for VolatilePtr<'_, T, A>
where
T: ?Sized,
{
fn clone(&self) -> Self {
*self
}
}
impl<T, A> fmt::Debug for VolatilePtr<'_, T, A>
where
T: ?Sized,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Pointer::fmt(&self.pointer.as_ptr(), f)
}
}
impl<T, A> fmt::Pointer for VolatilePtr<'_, T, A>
where
T: ?Sized,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Pointer::fmt(&self.pointer.as_ptr(), f)
}
}
impl<T, A> PartialEq for VolatilePtr<'_, T, A>
where
T: ?Sized,
{
fn eq(&self, other: &Self) -> bool {
core::ptr::eq(self.pointer.as_ptr(), other.pointer.as_ptr())
}
}
impl<T, A> Eq for VolatilePtr<'_, T, A> where T: ?Sized {}
impl<T, A> PartialOrd for VolatilePtr<'_, T, A>
where
T: ?Sized,
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<T, A> Ord for VolatilePtr<'_, T, A>
where
T: ?Sized,
{
fn cmp(&self, other: &Self) -> Ordering {
#[allow(ambiguous_wide_pointer_comparisons)]
Ord::cmp(&self.pointer.as_ptr(), &other.pointer.as_ptr())
}
}
impl<T, A> hash::Hash for VolatilePtr<'_, T, A>
where
T: ?Sized,
{
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.pointer.as_ptr().hash(state);
}
}