Created
April 15, 2015 17:37
-
-
Save jimblandy/0deb0555a5c5761ffa5d to your computer and use it in GitHub Desktop.
Implicit Deref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod implicit_deref { | |
use std::ops::Deref; | |
struct T(i32); | |
struct S<'a>(&'a T); | |
impl<'a> Deref for S<'a> { | |
type Target = T; | |
fn deref(&self) -> &T { &self.0; } | |
} | |
fn f(t: T, n: i32) { assert_eq!(n, t.0); } | |
#[test] | |
fn test() { | |
let t = T(42); | |
let s = S(&t); | |
f(s, 42); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dies with: