Trait scale_info::prelude::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<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<L, R> Deref for Either<L, R> where
    L: Deref,
    R: Deref<Target = L::Target>, 

impl<K, V, S> Deref for BoundedBTreeMap<K, V, S> where
    K: Ord

impl<T, S> Deref for BoundedBTreeSet<T, S> where
    T: Ord

impl<T, S> Deref for BoundedVec<T, S>

impl<T, S> Deref for WeakBoundedVec<T, S>

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, N> Deref for GenericArray<T, N> where
    N: ArrayLength<T>, 

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

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<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<'a, T: EncodeLike<U>, U: Encode> Deref for Ref<'a, T, U>

impl Deref for Literal

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<'a, T> Deref for ApiRef<'a, T>

impl Deref for Signature

impl Deref for Signature

impl Deref for Signature

impl Deref for Public

impl Deref for Public

impl Deref for Bytes

impl<Xt> Deref for ExtrinsicWrapper<Xt>

impl Deref for Timestamp

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<A: Array> Deref for ArrayVec<A>

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

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

impl<E> Deref for FormattedFields<E>

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