Trait sp_std::ops::Deref

1.0.0 · source · []
pub trait Deref {
    type Target: ?Sized;
    fn deref(&self) -> &Self::Target;
}
Expand description

Used for immutable dereferencing operations, like *v.

In addition to being used for explicit dereferencing operations with the (unary) * operator in immutable contexts, Deref is also used implicitly by the compiler in many circumstances. This mechanism is called Deref coercion’. In mutable contexts, DerefMut is used.

Implementing Deref for smart pointers makes accessing the data behind them convenient, which is why they implement Deref. On the other hand, the rules regarding Deref and DerefMut were designed specifically to accommodate smart pointers. Because of this, Deref should only be implemented for smart pointers to avoid confusion.

For similar reasons, this trait should never fail. Failure during dereferencing can be extremely confusing when Deref is invoked implicitly.

More on Deref coercion

If T implements Deref<Target = U>, and x is a value of type T, then:

  • In immutable contexts, *x (where T is neither a reference nor a raw pointer) is equivalent to *Deref::deref(&x).
  • Values of type &T are coerced to values of type &U
  • T implicitly implements all the (immutable) methods of the type U.

For more details, visit the chapter in The Rust Programming Language as well as the reference sections on the dereference operator, method resolution and type coercions.

Examples

A struct with a single field which is accessible by dereferencing the struct.

use std::ops::Deref;

struct DerefExample<T> {
    value: T
}

impl<T> Deref for DerefExample<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.value
    }
}

let x = DerefExample { value: 'a' };
assert_eq!('a', *x);

Associated Types

The resulting type after dereferencing.

Required methods

Dereferences the value.

Implementations on Foreign Types

Implementors

impl<'a, S: 'a + ToOwned + ?Sized> Deref for ANSIGenericString<'a, S> where
    <S as ToOwned>::Owned: Debug

impl Deref for Error

impl<T, const CAP: usize> Deref for ArrayVec<T, CAP>

impl<const CAP: usize> Deref for ArrayString<CAP>

impl<T: ?Sized> Deref for MutexGuard<'_, T>

impl<T: ?Sized> Deref for MutexGuardArc<T>

impl<T: ?Sized> Deref for RwLockReadGuard<'_, T>

impl<T: ?Sized> Deref for RwLockUpgradableReadGuard<'_, T>

impl<T: ?Sized> Deref for RwLockWriteGuard<'_, T>

impl<T: ?Sized> Deref for MutexGuard<'_, T>

impl<T: ?Sized> Deref for MutexGuardArc<T>

impl Deref for PathBuf

impl<T, U> Deref for Framed<T, U>

impl<T, D> Deref for FramedRead<T, D>

impl<T, E> Deref for FramedWrite<T, E>

impl<O, V> Deref for BitArray<O, V> where
    O: BitOrder,
    V: BitView

impl<M, O, T> Deref for BitRef<'_, M, O, T> where
    M: Mutability,
    O: BitOrder,
    T: BitStore

impl<O, T> Deref for BitBox<O, T> where
    O: BitOrder,
    T: BitStore

impl<O, T> Deref for BitVec<O, T> where
    O: BitOrder,
    T: BitStore

impl Deref for BString

impl Deref for BStr

impl Deref for Bytes

impl Deref for BytesMut

impl<T> Deref for CachePadded<T>

impl<T: ?Sized + Pointable> Deref for Owned<T>

impl<T> Deref for CachePadded<T>

impl<T: ?Sized> Deref for ShardedLockReadGuard<'_, T>

impl<T: ?Sized> Deref for ShardedLockWriteGuard<'_, T>

impl<L, R> Deref for Either<L, R> where
    L: Deref,
    R: Deref<Target = L::Target>, 

impl<S: Stream + Unpin> Deref for BlockingStream<S>

impl Deref for WakerRef<'_>

impl<T: ?Sized> Deref for MutexGuard<'_, T>

impl<T: ?Sized, U: ?Sized> Deref for MappedMutexGuard<'_, T, U>

impl<T> Deref for BiLockGuard<'_, T>

impl<T, N> Deref for GenericArray<T, N> where
    N: ArrayLength<T>, 

impl<'input, Endian> Deref for EndianSlice<'input, Endian> where
    Endian: Endianity

impl Deref for Duration

impl Deref for Timestamp

impl Deref for IoVec

impl Deref for Array

impl Deref for Boolean

impl Deref for DataView

impl Deref for Error

impl Deref for EvalError

impl Deref for Function

impl Deref for Generator

impl Deref for Map

impl Deref for Iterator

impl Deref for Number

impl Deref for Date

impl Deref for Object

impl Deref for Proxy

impl Deref for RangeError

impl Deref for RegExp

impl Deref for Set

impl Deref for TypeError

impl Deref for UriError

impl Deref for WeakMap

impl Deref for WeakSet

impl Deref for Instance

impl Deref for LinkError

impl Deref for Module

impl Deref for Table

impl Deref for Global

impl Deref for Memory

impl Deref for JsString

impl Deref for Symbol

impl Deref for Collator

impl Deref for Promise

impl Deref for Int8Array

impl Deref for Int16Array

impl Deref for Int32Array

impl Deref for Uint8Array

impl<M: Metadata> Deref for IoHandler<M>

impl<T: PubSubMetadata, S: Middleware<T>> Deref for PubSubHandler<T, S>

impl<T> Deref for Sender<T>

impl Deref for Origin

impl Deref for Host

impl<T: Zeroize> Deref for AuthenticKeypair<T>

impl<TBehaviour, TInEvent, TOutEvent, THandler> Deref for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler> where
    THandler: IntoProtocolsHandler

impl Deref for Transport

impl Deref for Connection

impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Deref for MutexGuard<'a, R, T>

impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Deref for MappedMutexGuard<'a, R, T>

impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> Deref for ReentrantMutexGuard<'a, R, G, T>

impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> Deref for MappedReentrantMutexGuard<'a, R, G, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Deref for RwLockReadGuard<'a, R, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Deref for RwLockWriteGuard<'a, R, T>

impl<'a, R: RawRwLockUpgrade + 'a, T: ?Sized + 'a> Deref for RwLockUpgradableReadGuard<'a, R, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Deref for MappedRwLockReadGuard<'a, R, T>

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Deref for MappedRwLockWriteGuard<'a, R, T>

impl Deref for Mmap

impl Deref for MmapMut

impl Deref for ByteSlice

impl Deref for ByteVec

impl<'b> Deref for Probe<'_, 'b>

impl Deref for UnixReady

impl<T: Scalar, S> Deref for Matrix<T, U1, U1, S> where
    S: ContiguousStorage<T, U1, U1>, 

impl<T: Scalar, S> Deref for Matrix<T, U2, U1, S> where
    S: ContiguousStorage<T, U2, U1>, 

impl<T: Scalar, S> Deref for Matrix<T, U3, U1, S> where
    S: ContiguousStorage<T, U3, U1>, 

impl<T: Scalar, S> Deref for Matrix<T, U4, U1, S> where
    S: ContiguousStorage<T, U4, U1>, 

impl<T: Scalar, S> Deref for Matrix<T, U5, U1, S> where
    S: ContiguousStorage<T, U5, U1>, 

impl<T: Scalar, S> Deref for Matrix<T, U6, U1, S> where
    S: ContiguousStorage<T, U6, U1>, 

impl<T: Scalar, S> Deref for Matrix<T, U1, U2, S> where
    S: ContiguousStorage<T, U1, U2>, 

impl<T: Scalar, S> Deref for Matrix<T, U1, U3, S> where
    S: ContiguousStorage<T, U1, U3>, 

impl<T: Scalar, S> Deref for Matrix<T, U1, U4, S> where
    S: ContiguousStorage<T, U1, U4>, 

impl<T: Scalar, S> Deref for Matrix<T, U1, U5, S> where
    S: ContiguousStorage<T, U1, U5>, 

impl<T: Scalar, S> Deref for Matrix<T, U1, U6, S> where
    S: ContiguousStorage<T, U1, U6>, 

impl<T: Scalar, S> Deref for Matrix<T, U2, U2, S> where
    S: ContiguousStorage<T, U2, U2>, 

impl<T: Scalar, S> Deref for Matrix<T, U2, U3, S> where
    S: ContiguousStorage<T, U2, U3>, 

impl<T: Scalar, S> Deref for Matrix<T, U2, U4, S> where
    S: ContiguousStorage<T, U2, U4>, 

impl<T: Scalar, S> Deref for Matrix<T, U2, U5, S> where
    S: ContiguousStorage<T, U2, U5>, 

impl<T: Scalar, S> Deref for Matrix<T, U2, U6, S> where
    S: ContiguousStorage<T, U2, U6>, 

impl<T: Scalar, S> Deref for Matrix<T, U3, U2, S> where
    S: ContiguousStorage<T, U3, U2>, 

impl<T: Scalar, S> Deref for Matrix<T, U3, U3, S> where
    S: ContiguousStorage<T, U3, U3>, 

impl<T: Scalar, S> Deref for Matrix<T, U3, U4, S> where
    S: ContiguousStorage<T, U3, U4>, 

impl<T: Scalar, S> Deref for Matrix<T, U3, U5, S> where
    S: ContiguousStorage<T, U3, U5>, 

impl<T: Scalar, S> Deref for Matrix<T, U3, U6, S> where
    S: ContiguousStorage<T, U3, U6>, 

impl<T: Scalar, S> Deref for Matrix<T, U4, U2, S> where
    S: ContiguousStorage<T, U4, U2>, 

impl<T: Scalar, S> Deref for Matrix<T, U4, U3, S> where
    S: ContiguousStorage<T, U4, U3>, 

impl<T: Scalar, S> Deref for Matrix<T, U4, U4, S> where
    S: ContiguousStorage<T, U4, U4>, 

impl<T: Scalar, S> Deref for Matrix<T, U4, U5, S> where
    S: ContiguousStorage<T, U4, U5>, 

impl<T: Scalar, S> Deref for Matrix<T, U4, U6, S> where
    S: ContiguousStorage<T, U4, U6>, 

impl<T: Scalar, S> Deref for Matrix<T, U5, U2, S> where
    S: ContiguousStorage<T, U5, U2>, 

impl<T: Scalar, S> Deref for Matrix<T, U5, U3, S> where
    S: ContiguousStorage<T, U5, U3>, 

impl<T: Scalar, S> Deref for Matrix<T, U5, U4, S> where
    S: ContiguousStorage<T, U5, U4>, 

impl<T: Scalar, S> Deref for Matrix<T, U5, U5, S> where
    S: ContiguousStorage<T, U5, U5>, 

impl<T: Scalar, S> Deref for Matrix<T, U5, U6, S> where
    S: ContiguousStorage<T, U5, U6>, 

impl<T: Scalar, S> Deref for Matrix<T, U6, U2, S> where
    S: ContiguousStorage<T, U6, U2>, 

impl<T: Scalar, S> Deref for Matrix<T, U6, U3, S> where
    S: ContiguousStorage<T, U6, U3>, 

impl<T: Scalar, S> Deref for Matrix<T, U6, U4, S> where
    S: ContiguousStorage<T, U6, U4>, 

impl<T: Scalar, S> Deref for Matrix<T, U6, U5, S> where
    S: ContiguousStorage<T, U6, U5>, 

impl<T: Scalar, S> Deref for Matrix<T, U6, U6, S> where
    S: ContiguousStorage<T, U6, U6>, 

impl<T> Deref for Unit<T>

impl<T: Scalar> Deref for Point<T, 1>

impl<T: Scalar> Deref for Point<T, 2>

impl<T: Scalar> Deref for Point<T, 3>

impl<T: Scalar> Deref for Point<T, 4>

impl<T: Scalar> Deref for Point<T, 5>

impl<T: Scalar> Deref for Point<T, 6>

impl<T: Scalar + SimdValue> Deref for Quaternion<T>

impl<T: Scalar> Deref for Translation<T, 1>

impl<T: Scalar> Deref for Translation<T, 2>

impl<T: Scalar> Deref for Translation<T, 3>

impl<T: Scalar> Deref for Translation<T, 4>

impl<T: Scalar> Deref for Translation<T, 5>

impl<T: Scalar> Deref for Translation<T, 6>

impl<T, F: FnOnce() -> T> Deref for Lazy<T, F>

impl<T, F: FnOnce() -> T> Deref for Lazy<T, F>

impl<O, H> Deref for OwningHandle<O, H> where
    O: StableAddress,
    H: Deref

impl<O, T: ?Sized> Deref for OwningRef<O, T>

impl<O, T: ?Sized> Deref for OwningRefMut<O, T>

impl<'a, T: EncodeLike<U>, U: Encode> Deref for Ref<'a, T, U>

impl<T> Deref for SendWrapper<T>

impl<T> Deref for Entry<T>

impl Deref for Literal

impl<'a> Deref for DBPinnableSlice<'a>

impl Deref for Config

impl<T> Deref for SlotDuration<T>

impl<T, F, S> Deref for ScopeGuard<T, F, S> where
    F: FnOnce(T),
    S: Strategy

impl<'a, T, C> Deref for Ref<'a, T, C> where
    T: Clear + Default,
    C: Config

impl<'a, T, C: Config> Deref for RefMut<'a, T, C> where
    T: Clear + Default,
    C: Config

impl<T, C> Deref for OwnedRef<T, C> where
    T: Clear + Default,
    C: Config

impl<T, C> Deref for OwnedRefMut<T, C> where
    T: Clear + Default,
    C: Config

impl<'a, T, C: Config> Deref for Entry<'a, T, C>

impl<T, C> Deref for OwnedEntry<T, C> where
    C: Config

impl<A: Array> Deref for SmallVec<A>

impl<'s> Deref for SockRef<'s>

impl<'a> Deref for MaybeUninitSlice<'a>

impl<'a, T> Deref for ApiRef<'a, T>

impl Deref for Signature

impl Deref for Signature

impl Deref for Signature

impl Deref for Slot

impl Deref for VRFOutput

impl Deref for VRFProof

impl Deref for Public

impl Deref for Public

impl Deref for Bytes

impl Deref for Keyring

impl Deref for Keyring

impl<Xt> Deref for ExtrinsicWrapper<Xt>

impl<'a, T: ?Sized> Deref for MutexGuard<'a, T>

impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T>

impl<'rwlock, T: ?Sized> Deref for RwLockUpgradeableGuard<'rwlock, T>

impl<'rwlock, T: ?Sized> Deref for RwLockWriteGuard<'rwlock, T>

impl Deref for Underscore

impl Deref for Add

impl Deref for And

impl Deref for At

impl Deref for Bang

impl Deref for Caret

impl Deref for Colon

impl Deref for Comma

impl Deref for Div

impl Deref for Dollar

impl Deref for Dot

impl Deref for Eq

impl Deref for Gt

impl Deref for Lt

impl Deref for Or

impl Deref for Pound

impl Deref for Question

impl Deref for Rem

impl Deref for Semi

impl Deref for Star

impl Deref for Sub

impl Deref for Tilde

impl<'c, 'a> Deref for StepCursor<'c, 'a>

impl Deref for TempPath

impl<A: Array> Deref for ArrayVec<A>

impl<'s, T> Deref for SliceVec<'s, T>

impl<A: Array> Deref for TinyVec<A>

impl<T: ?Sized> Deref for MutexGuard<'_, T>

impl<T: ?Sized> Deref for OwnedMutexGuard<T>

impl<T: ?Sized> Deref for RwLockReadGuard<'_, T>

impl<T: ?Sized> Deref for RwLockWriteGuard<'_, T>

impl<T> Deref for Ref<'_, T>

impl<T> Deref for LockGuard<T>

impl<'a, T: 'a> Deref for Ref<'a, T>

impl<E> Deref for FormattedFields<E>

impl<'a, T> Deref for Locked<'a, T>

impl<S> Deref for Ascii<S>

impl<S> Deref for UniCase<S>

impl<T: FromWasmAbi + 'static> Deref for JsStatic<T>

impl<T> Deref for Clamped<T>

impl Deref for FuncRef

impl Deref for GlobalRef

impl Deref for MemoryRef

impl Deref for ModuleRef

impl Deref for TableRef

impl<T: Binary> Deref for FmtBinary<T>

impl<T: Display> Deref for FmtDisplay<T>

impl<T: LowerExp> Deref for FmtLowerExp<T>

impl<T: LowerHex> Deref for FmtLowerHex<T>

impl<T: Octal> Deref for FmtOctal<T>

impl<T: Pointer> Deref for FmtPointer<T>

impl<T: UpperExp> Deref for FmtUpperExp<T>

impl<T: UpperHex> Deref for FmtUpperHex<T>

impl<Z> Deref for Zeroizing<Z> where
    Z: Zeroize