Trait std::ops::DerefStable [-] [+] [src]

pub trait Deref {
    type Target;

    fn deref(&'a self) -> &'a <Self as Deref>::Target;
}

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

Example

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<'a>(&'a self) -> &'a T { &self.value } } fn main() { let x = DerefExample { value: 'a' }; assert_eq!('a', *x); }
use std::ops::Deref;

struct DerefExample<T> {
    value: T
}

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

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

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

Associated Types

type Target

Required Methods

fn deref(&'a self) -> &'a <Self as Deref>::Target

The method called to dereference a value

Implementors