# Trait std::ops::Deref 1.0.0 [−] [src]

    #[lang = "deref"]
    pub trait Deref {
        type Target: ?Sized;
        fn deref(&self) -> &Self::Target;
    }

The `Deref` trait is used to specify the functionality of dereferencing operations, like `*v`.

`Deref` also enables '`Deref` coercions'.

# Examples

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

    use std::ops::Deref;

    struct DerefExample<T> {
        value: T
    }

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

        fn deref(&self) -> &T {
            &self.value
        }
    }

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

## Associated Types

### `type Target: ?Sized`

The resulting type after dereferencing

## Required Methods

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

The method called to dereference a value

## Implementors

- `impl<'b, T> Deref for Ref<'b, T> where
  T: ?Sized,`
- `impl<'a, T> Deref for &'a T where
  T: ?Sized,`
- `impl<'a, T> Deref for &'a mut T where
  T: ?Sized,`
- `impl<T> Deref for ManuallyDrop<T>`
- `impl<'b, T> Deref for RefMut<'b, T> where
  T: ?Sized,`
- `impl Deref for String`
- `impl<T> Deref for Rc<T> where
  T: ?Sized,`
- `impl<T> Deref for Vec<T>`
- `impl<'a, T> Deref for PeekMut<'a, T> where
  T: Ord,`
- `impl<T> Deref for Arc<T> where
  T: ?Sized,`
- `impl<'a, B> Deref for Cow<'a, B> where
  B: ToOwned + ?Sized,`
- `impl<T> Deref for Box<T> where
  T: ?Sized,`
- `impl Deref for CString`
- `impl Deref for OsString`
- `impl<T> Deref for AssertUnwindSafe<T>`
- `impl Deref for PathBuf`
- `impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T>`
- `impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T>`
- `impl<'rwlock, T: ?Sized> Deref for RwLockWriteGuard<'rwlock, T>`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)