Rust 取消引用强制
例子
给定两种类型TandU,&T将强制(隐式转换)为&U当且仅当T实现Deref
这允许我们做这样的事情:
fn foo(a: &[i32]) {
//代码
}
fn bar(s: &str) {
//代码
}
let v = vec![1, 2, 3];
foo(&v); // &Vec coerces into &[i32] because Vec impls Deref
let s = "Hello world".to_string();
let rc = Rc::new(s);
// This works because Rc impls Deref ∴ &Rc coerces into
// &String which coerces into &str. This happens as much as needed at compile time.
bar(&rc);
热门推荐
10 给宝贝开学祝福语简短
11 爸爸爱你祝福语大全简短
12 打牌翻盘祝福语简短
13 新婚过年祝福语大全简短
14 家长祝福语大全简短内容
15 宝宝新生入学祝福语简短
16 送个姐妹生日祝福语简短
17 长辈钻石婚祝福语简短
18 教练生日祝福语 简短独特