Created
June 15, 2017 03:06
-
-
Save anonymous/4b614b3d05ef5b7d340c51646b6d1e52 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
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
trait Hoge<A> { | |
fn aaa(&self) -> A; | |
fn bbb(&self) -> i32; | |
} | |
fn call_hoge_i32<X: Hoge<i32>>(hoge: &X) { | |
println!("aaa => {}", hoge.aaa()); | |
println!("bbb => {}", hoge.bbb()); | |
} | |
fn call_hoge_string<X: Hoge<String>>(hoge: &X) { | |
println!("aaa => {}", hoge.aaa()); | |
println!("bbb => {}", hoge.bbb()); | |
} | |
fn call_hoge_generic<T: std::fmt::Display, X: Hoge<T>>(hoge: &X) { | |
println!("aaa => {}", hoge.aaa()); | |
println!("bbb => {}", hoge.bbb()); | |
} | |
struct Cat; | |
impl Hoge<i32> for Cat { | |
fn aaa(&self) -> i32 { | |
return 11 | |
} | |
fn bbb(&self) -> i32 { | |
return 22 | |
} | |
} | |
impl Hoge<String> for Cat { | |
fn aaa(&self) -> String { | |
return "sss".to_string() | |
} | |
fn bbb(&self) -> i32 { | |
return 33 | |
} | |
} | |
fn main() { | |
let cat = Cat; | |
call_hoge_i32(&cat); | |
call_hoge_string(&cat); | |
call_hoge_generic(&cat); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment