mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-24 21:32:15 +08:00
22 lines
308 B
Rust
Executable File
22 lines
308 B
Rust
Executable File
trait Animal {
|
|
fn baby_name() -> String;
|
|
}
|
|
|
|
struct Dog;
|
|
|
|
impl Dog {
|
|
fn baby_name() -> String {
|
|
String::from("Spot")
|
|
}
|
|
}
|
|
|
|
impl Animal for Dog {
|
|
fn baby_name() -> String {
|
|
String::from("puppy")
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
println!("A baby dog is called a {}", Dog::baby_name());
|
|
}
|