mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-04-22 13:38:04 +08:00
24 lines
347 B
Rust
Executable File
24 lines
347 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")
|
|
}
|
|
}
|
|
|
|
// ANCHOR: here
|
|
fn main() {
|
|
println!("A baby dog is called a {}", Animal::baby_name());
|
|
}
|
|
// ANCHOR_END: here
|