Trait atomic_ring_buffer::InvariantAsMut [] [src]

pub unsafe trait InvariantAsMut<T: ?Sized>: AsMut<T> + AsRef<T> { }

A marker trait indicating that as_mut() and as_ref() always return the same pointer.

When using as_ref() or as_mut(), it is generally reasonable to assume that:

  • both return a pointer to the same data, and
  • this pointer never changes.

These assumptions are vital when writing unsafe code.

However, it is legal (although likely counterproductive) to implement as_ref() and as_mut() that violate this assumption, and when coupled with unsafe code this results in breach of memory safety. Hence, this (unsafe to implement) trait is used to indicate that the implementation is sane.

Implementors