Trait uninit_tools::traits::TrustedDeref[][src]

pub unsafe trait TrustedDeref: Deref { }

A marker trait for implementations of Deref that come with the additional guarantee that:

  1. The [Deref::deref] method will always return a slice with the same length, if the dereference target happens to a slice ([T]);
  2. The [DerefMut::deref_mut] method, like [Deref::deref] will also always return a slice with the same length, and that it cannot change the length in any way when calling this trait method;
  3. The target slice must always point to the same memory, although the address is allowed to change. In other words, any modifications to the target type, must be visible when calling the dereference methods again.

This is implemented for most of the familiar types in the standard library, e.g. Box, Vec, [Ref], etc.

This comes with some exceptions: for example do note that this only affects the [Deref] and [DerefMut] trait methods. There can still be ways to modify the length of the slice, either via interior mutability or via mutable references, accessible to safe code, so long as this is not in the dereference traits.

The aim of this trait is to force that when using whatever slice a [BufferInitializer] backs, it can be confident that the initializedness counter it stores will always be equal to the total length when the initializer is full. A [Deref] implementation that lacks the guarantee of this trait, would cause Undefined Behavior in the very building blocks of this library, otherwise.

Note that this is also fully orthogonal to StableDeref. So long as [BufferInitializer] can make assumptions about the length always being correct, the actual address of the memory is of no importance. However, implementing StableDeref means that invariant 3 is always upheld, but it is not clear at the moment whether that also applies to invariant 1 and 2.

Implementations on Foreign Types

impl<'a, T: ?Sized> TrustedDeref for &'a T[src]

impl<'a, T: ?Sized> TrustedDeref for &'a mut T[src]

impl<T> TrustedDeref for Vec<T>[src]

impl<T: ?Sized> TrustedDeref for Box<T>[src]

impl<T: ?Sized> TrustedDeref for Arc<T>[src]

impl<T: ?Sized> TrustedDeref for Rc<T>[src]

impl<'a, T: ?Sized> TrustedDeref for Ref<'a, T>[src]

impl<'a, T: ?Sized> TrustedDeref for RefMut<'a, T>[src]

impl<'a, T: ?Sized> TrustedDeref for MutexGuard<'a, T>[src]

impl<'a, T: ?Sized> TrustedDeref for RwLockReadGuard<'a, T>[src]

impl<'a, T: ?Sized> TrustedDeref for RwLockWriteGuard<'a, T>[src]

impl TrustedDeref for String[src]

impl TrustedDeref for CString[src]

impl TrustedDeref for OsString[src]

impl TrustedDeref for PathBuf[src]

impl<T: Deref> TrustedDeref for Pin<T>[src]

impl<'a, T: ToOwned> TrustedDeref for Cow<'a, T>[src]

Loading content...

Implementors

Loading content...