rust/src/test/ui/deref-on-ref.rs

20 lines
303 B
Rust
Raw Normal View History

// run-pass
// Test that `&T` and `&mut T` implement `Deref<T>`
use std::ops::Deref;
2015-01-01 13:53:20 -06:00
fn deref<U:Copy,T:Deref<Target=U>>(t: T) -> U {
*t
}
fn main() {
let x: isize = 3;
let y = deref(&x);
assert_eq!(y, 3);
let mut x: isize = 4;
let y = deref(&mut x);
assert_eq!(y, 4);
}