Created
May 28, 2017 02:02
-
-
Save syusui-s/caef481977731313d960e9631e06af90 to your computer and use it in GitHub Desktop.
This file contains 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
use std::ops::Deref; | |
struct DerefExample<T> { | |
value: T | |
} | |
impl<T> Deref for DerefExample<T> { | |
type Target = T; | |
fn deref(&self) -> &T { | |
&self.value | |
} | |
} | |
struct NonDeref<T> { | |
value: T | |
} | |
fn main() { | |
let x = DerefExample{ value: "abc" }; | |
let s1 : String = x.to_owned(); | |
let y = NonDeref{ value: "abc" }; | |
// let s2 : String = y.to_owned(); // <- エラー発生 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment