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);

Required Associated Types§

The resulting type after dereferencing.

Required Methods§

Dereferences the value.

Implementors§

impl<K, V, S> Deref for AHashMap<K, V, S>

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

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> Deref for SequenceVec<T>

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 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<T, U> Deref for Cow<'_, T, U>where
    T: Beef + ?Sized,
    U: Capacity,

impl Deref for Signature

impl<A, O> Deref for BitArray<A, O>where
    A: BitViewSized,
    O: BitOrder,

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

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

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

impl Deref for BString

impl Deref for BStr

impl Deref for Bytes

impl Deref for BytesMut

impl Deref for Families

impl Deref for HasAtomics

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<T> Deref for NonZero<T>where
    T: Zero,

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

impl<C> Deref for NonZeroScalar<C>where
    C: Curve + ScalarArithmetic,

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

impl Deref for WakerRef<'_>

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

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

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<W: Writer> Deref for DebugAbbrev<W>

impl<W: Writer> Deref for DebugFrame<W>

impl<W: Writer> Deref for EhFrame<W>

impl<W: Writer> Deref for DebugLine<W>

impl<W: Writer> Deref for DebugLoc<W>

impl<W: Writer> Deref for DebugLocLists<W>

impl<W: Writer> Deref for DebugRanges<W>

impl<W: Writer> Deref for DebugRngLists<W>

impl<W: Writer> Deref for DebugStr<W>

impl<W: Writer> Deref for DebugLineStr<W>

impl<W: Writer> Deref for DebugInfo<W>

impl Deref for Duration

impl Deref for Timestamp

impl<Balance: Default> Deref for BalanceUpdate<Balance>

impl<Target: FilelikeViewType> Deref for FilelikeView<'_, Target>

impl<Target: SocketlikeViewType> Deref for SocketlikeView<'_, Target>

impl Deref for Array

impl Deref for BigInt

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 Deref for Origin

impl Deref for Host

impl<Context> Deref for RpcModule<Context>

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

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<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 Deref for Buffer

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

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

impl<T: Float> Deref for OrderedFloat<T>

impl<T: Float> Deref for NotNan<T>

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<T: Config> Deref for SignedSubmissions<T>

impl<T: Config> Deref for BondedPool<T>

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

impl<T> Deref for SendWrapper<T>

impl<'a, G> Deref for Frozen<'a, G>

impl<'b, T> Deref for Ptr<'b, T>

impl Deref for OurView

impl<T> Deref for MeteredReceiver<T>

impl<T> Deref for MeteredSender<T>

impl<T> Deref for MaybeTimeOfFlight<T>

impl Deref for Literal

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

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

impl<T> Deref for Retrieved<T>

impl Deref for Connection

impl<T> Deref for ConnectionCommon<T>

impl<'a, T> Deref for SharedDataLocked<'a, 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> 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<H, T> Deref for Compact<H, T>

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

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

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

impl<Xt> Deref for ExtrinsicWrapper<Xt>

impl Deref for Timestamp

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<T, F> Deref for Lazy<T, F>where
    F: FnOnce() -> T,

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

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

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

impl<T> Deref for Static<T>

impl<T> Deref for ConstStatic<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 Deref for Word<'_>

impl<C> Deref for ReadHalf<C>where
    C: Read,

impl<C> Deref for WriteHalf<C>where
    C: Write,

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<'a, T: ?Sized> Deref for MappedMutexGuard<'a, T>

impl<T: ?Sized, U: ?Sized> Deref for OwnedRwLockReadGuard<T, U>

impl<T: ?Sized, U: ?Sized> Deref for OwnedRwLockMappedWriteGuard<T, U>

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

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

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

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

impl<E> Deref for FormattedFields<E>

impl Deref for Bytes

impl Deref for Message

impl Deref for DEFAULT

impl Deref for IP6_ARPA

impl Deref for LOCALHOST

impl Deref for IP6_ARPA_1

impl Deref for LOCAL

impl Deref for INVALID

impl Deref for ONION

impl Deref for ZoneUsage

impl Deref for HEX

impl Deref for DnsRequest

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 Deref for MmapVec

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<T> Deref for FmtList<T>where
    for<'a> &'a T: IntoIterator,

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