Trait std::convert::AsRef [] [src]

pub trait AsRef<T> where T: ?Sized {
    fn as_ref(&self) -> &T;
}

A cheap, reference-to-reference conversion.

AsRef is very similar to, but different than, Borrow. See the book for more.

Examples

Both String and &str implement AsRef<str>:

fn is_hello<T: AsRef<str>>(s: T) {
   assert_eq!("hello", s.as_ref());
}

let s = "hello";
is_hello(s);

let s = "hello".to_string();
is_hello(s);

Required Methods

fn as_ref(&self) -> &T

Performs the conversion.

Implementors