Created
January 12, 2017 01:23
-
-
Save axross/8a5232f1ccf0b336270101bad6f2c2f9 to your computer and use it in GitHub Desktop.
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
| Compiling study_lang v0.1.0 (file:///Users/axross/Dropbox/Workspace/study-rust/study_lang) | |
| error[E0277]: the trait bound `Humanoid: Walkable` is not satisfied | |
| --> src/main.rs:68:3 | |
| | | |
| 68 | shift(humanoid); | |
| | ^^^^^ the trait `Walkable` is not implemented for `Humanoid` | |
| | | |
| = note: required by `shift` | |
| error: aborting due to previous error | |
| error: Could not compile `study_lang`. | |
| To learn more, run the command again with --verbose. |
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
| trait Walkable { | |
| fn walk(&self) -> (); | |
| } | |
| trait AlternativeWalkable { | |
| fn walk(&self) -> (); | |
| } | |
| struct Human { | |
| name: String, | |
| } | |
| struct Dog { | |
| breed: String, | |
| } | |
| struct Humanoid { | |
| id: i32, | |
| } | |
| impl Human { | |
| fn new(name: String) -> Human { | |
| Human { name: name } | |
| } | |
| } | |
| impl Dog { | |
| fn new(breed: String) -> Dog { | |
| Dog { breed: breed } | |
| } | |
| } | |
| impl Humanoid { | |
| fn new(id: i32) -> Humanoid { | |
| Humanoid { id: id } | |
| } | |
| } | |
| impl Walkable for Human { | |
| fn walk(&self) { | |
| println!("{} walks on the ground", self.name); | |
| } | |
| } | |
| impl Walkable for Dog { | |
| fn walk(&self) { | |
| println!("{} walks on the ground", self.breed); | |
| } | |
| } | |
| impl AlternativeWalkable for Humanoid { | |
| fn walk(&self) { | |
| println!("Humanoid(id:{}) emulates walking", self.id); | |
| } | |
| } | |
| fn shift<T: Walkable>(target: T) { | |
| target.walk(); | |
| } | |
| fn main() { | |
| let human = Human::new("John".to_string()); | |
| let dog = Dog::new("German Shepherd".to_string()); | |
| let humanoid = Humanoid::new(31); | |
| shift(human); | |
| shift(dog); | |
| shift(humanoid); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment