[][src]Function tao_of_rust::ch03::type_cast::auto_deref

pub fn auto_deref()

类型转换:自动解引用(For SmartPointer)

Base usage: Vec<T>实现了Deref<Target=[T]>

fn foo(s: &[i32]){
    println!("{:?}", s[0]);
}

let v = vec![1,2,3];
foo(&v)Run

Base usage: String实现了Deref<Target=str>

let a = "hello".to_string();
let b = " world".to_string();
let c = a + &b;
println!("{:?}", c); // "hello world"Run

Base usage: Rc<T>实现了Deref<Target<T>>

use std::rc::Rc;
let x = Rc::new("hello");
println!("{:?}", x.chars());Run