Trait sp_std::ops::Deref

1.0.0 · source ·
pub trait Deref {
    type Target: ?Sized;

    // Required method
    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§

source

type Target: ?Sized

The resulting type after dereferencing.

Required Methods§

source

fn deref(&self) -> &Self::Target

Dereferences the value.

Implementors§

source§

impl Deref for CString

§

type Target = CStr

source§

impl Deref for String

§

type Target = str

source§

impl Deref for OsString

source§

impl Deref for PathBuf

§

type Target = Path

1.36.0 · source§

impl<'a> Deref for IoSlice<'a>

§

type Target = [u8]

1.36.0 · source§

impl<'a> Deref for IoSliceMut<'a>

§

type Target = [u8]

source§

impl<'a, 'f> Deref for VaList<'a, 'f>where 'f: 'a,

§

type Target = VaListImpl<'f>

source§

impl<B> Deref for Cow<'_, B>where B: ToOwned + ?Sized, <B as ToOwned>::Owned: Borrow<B>,

§

type Target = B

1.33.0 · source§

impl<P> Deref for Pin<P>where P: Deref,

§

type Target = <P as Deref>::Target

source§

impl<T> Deref for &Twhere T: ?Sized,

§

type Target = T

source§

impl<T> Deref for &mut Twhere T: ?Sized,

§

type Target = T

source§

impl<T> Deref for ThinBox<T>where T: ?Sized,

§

type Target = T

source§

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

§

type Target = T

source§

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

§

type Target = T

1.20.0 · source§

impl<T> Deref for ManuallyDrop<T>where T: ?Sized,

§

type Target = T

source§

impl<T> Deref for Rc<T>where T: ?Sized,

§

type Target = T

source§

impl<T> Deref for Arc<T>where T: ?Sized,

§

type Target = T

source§

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

§

type Target = T

source§

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

§

type Target = T

source§

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

§

type Target = T

1.9.0 · source§

impl<T> Deref for AssertUnwindSafe<T>

§

type Target = T

source§

impl<T, A> Deref for Box<T, A>where A: Allocator, T: ?Sized,

§

type Target = T

source§

impl<T, A> Deref for Vec<T, A>where A: Allocator,

§

type Target = [T]

1.12.0 · source§

impl<T, A> Deref for PeekMut<'_, T, A>where T: Ord, A: Allocator,

§

type Target = T

source§

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

§

type Target = T

source§

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

§

type Target = T

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<const CAP: usize> Deref for ArrayString<CAP>

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

impl<T> Deref for SequenceVec<T>

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

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

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

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

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

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

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

impl<T, U> Deref for Cow<'_, T, U>where T: Beef + ?Sized, U: Capacity,

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

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

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

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

impl Deref for BStr

impl Deref for BString

impl Deref for BytesMut

impl Deref for Bytes

impl Deref for HasAtomics

impl Deref for Families

impl Deref for OsStr

impl Deref for Str

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

impl Deref for CFData

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

impl Deref for Function

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

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

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

impl<T> Deref for CachePadded<T>

impl<T> Deref for NonZero<T>where T: Zero,

impl<'a> Deref for Ia5StringRef<'a>

impl<'a> Deref for Utf8StringRef<'a>

impl<'a> Deref for TeletexStringRef<'a>

impl<'a> Deref for VideotexStringRef<'a>

impl<'a> Deref for PrintableStringRef<'a>

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

impl<T: ?Sized> Deref for OwnedMutexGuard<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 Timestamp

impl Deref for Duration

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

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

impl Deref for Date

impl Deref for Array

impl Deref for Int32Array

impl Deref for LinkError

impl Deref for UriError

impl Deref for Int8Array

impl Deref for Uint8Array

impl Deref for Table

impl Deref for Iterator

impl Deref for Int16Array

impl Deref for Object

impl Deref for BigInt

impl Deref for Symbol

impl Deref for Number

impl Deref for Generator

impl Deref for Boolean

impl Deref for WeakSet

impl Deref for WeakMap

impl Deref for Set

impl Deref for Map

impl Deref for JsString

impl Deref for EvalError

impl Deref for Module

impl Deref for Global

impl Deref for Instance

impl Deref for Function

impl Deref for Collator

impl Deref for TypeError

impl Deref for DataView

impl Deref for Error

impl Deref for Memory

impl Deref for Proxy

impl Deref for RegExp

impl Deref for RangeError

impl Deref for Promise

impl<Context> Deref for RpcModule<Context>

impl Deref for Transport

impl Deref for Connection

impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Deref for MappedMutexGuard<'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 MappedRwLockWriteGuard<'a, R, 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 MappedRwLockReadGuard<'a, R, T>

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

impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Deref for RwLockReadGuard<'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, T: ?Sized + 'a> Deref for MutexGuard<'a, R, T>

impl Deref for MmapMut

impl Deref for Mmap

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, U5, U3, S>where S: ContiguousStorage<T, U5, U3>,

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

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

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, U2, U1, S>where S: ContiguousStorage<T, U2, U1>,

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, U5, S>where S: ContiguousStorage<T, U4, U5>,

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, U4, U4, S>where S: ContiguousStorage<T, U4, U4>,

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

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

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, U4, U6, S>where S: ContiguousStorage<T, U4, U6>,

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

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

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, U6, U6, S>where S: ContiguousStorage<T, U6, U6>,

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, U6, U1, S>where S: ContiguousStorage<T, U6, U1>,

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, U6, U5, S>where S: ContiguousStorage<T, U6, U5>,

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, U1, U2, S>where S: ContiguousStorage<T, U1, U2>,

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

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

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

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

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

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

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, U5, U1, S>where S: ContiguousStorage<T, U5, U1>,

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

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, U3, U5, S>where S: ContiguousStorage<T, U3, U5>,

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, U2, U6, S>where S: ContiguousStorage<T, U2, U6>,

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

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

impl<T> Deref for Unit<T>

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

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, U4, U1, S>where S: ContiguousStorage<T, U4, U1>,

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

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

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

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, U3, U4, S>where S: ContiguousStorage<T, U3, U4>,

impl<I> Deref for Located<I>

impl<I> Deref for Streaming<I>

impl<I, S> Deref for Stateful<I, S>

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<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<'b, T> Deref for Ptr<'b, T>

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

impl Deref for OurView

impl<T> Deref for MeteredReceiver<T>

impl<T> Deref for MaybeTimeOfFlight<T>

impl<T> Deref for MeteredSender<T>

impl Deref for Literal

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

impl Deref for SafeString

impl Deref for SafeVec

impl<T> Deref for ConnectionCommon<T>

impl<T> Deref for Retrieved<T>

impl Deref for Connection

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<T, C> Deref for OwnedRefMut<T, C>where T: Clear + Default, C: Config,

impl<T, C> Deref for OwnedRef<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, 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<A: Array> Deref for SmallVec<A>

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

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

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

impl Deref for Signature

impl Deref for Signature

impl Deref for Signature

impl Deref for Signature

impl Deref for Slot

impl Deref for VRFProof

impl Deref for VRFOutput

impl<'a, T, S> Deref for BoundedSlice<'a, T, S>

impl Deref for Public

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

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

impl Deref for Bytes

impl Deref for Public

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

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

impl Deref for Keyring

impl Deref for Keyring

impl<H, T> Deref for Compact<H, T>

impl<Xt> Deref for ExtrinsicWrapper<Xt>

impl Deref for Timestamp

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

impl<T, G> Deref for LazyFinalize<T, G>where G: 'static + Generator<T> + Sync, T: 'static + Sync + Finaly,

impl<T> Deref for ConstStatic<T>

impl<T, G> Deref for LesserLazyFinalize<T, G>where G: 'static + Generator<T> + Sync, T: 'static + Sync + Finaly,

impl<T> Deref for Static<T>

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

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

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

impl<T, G> Deref for Lazy<T, G>where G: Generator<T>,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

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

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

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

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

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

impl<T, G> Deref for LesserLazy<T, G>where G: 'static + Generator<T>, T: 'static,

impl<T, G> Deref for UnSyncLazy<T, G>where G: Generator<T>,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

impl<'a, T> Deref for WriteGuard<'a, T>where T: 'static,

impl<'a, T> Deref for ReadGuard<'a, T>where T: 'static,

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

impl Deref for Or

impl Deref for Underscore

impl Deref for Colon

impl Deref for Dollar

impl Deref for Tilde

impl Deref for Div

impl Deref for Caret

impl Deref for Semi

impl Deref for Pound

impl Deref for Sub

impl Deref for At

impl Deref for Lt

impl Deref for Add

impl Deref for Eq

impl Deref for Question

impl Deref for Gt

impl Deref for Rem

impl Deref for Dot

impl Deref for Comma

impl Deref for Bang

impl Deref for Star

impl Deref for And

impl Deref for TempPath

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl Deref for Document

impl Deref for Key

impl<'k> Deref for KeyMut<'k>

impl<E> Deref for FormattedFields<E>

impl Deref for Bytes

impl Deref for Message

impl Deref for ZoneUsage

impl Deref for DEFAULT

impl Deref for HEX

impl Deref for INVALID

impl Deref for MDNS_IPV4

impl Deref for LOCAL

impl Deref for IP6_ARPA

impl Deref for ONION

impl Deref for DnsRequest

impl Deref for MDNS_IPV6

impl Deref for LOCALHOST

impl Deref for IP6_ARPA_1

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

impl<T> Deref for Clamped<T>

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

impl Deref for ModuleRef

impl Deref for FuncRef

impl Deref for MemoryRef

impl Deref for GlobalRef

impl Deref for TableRef

impl Deref for MmapVec

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

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

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

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

impl<T> Deref for FmtList<T>where for<'a> &'a T: IntoIterator,

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

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

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

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

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