diff options
author | tom barrett <spalf0@gmail.com> | 2018-02-22 04:32:51 -0600 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2018-02-22 04:32:51 -0600 |
commit | c8d308a566c9e3e5be85e0e67082a06c3420a72b (patch) | |
tree | dbbd0ce6581a60a44b8dc978abc435829d874e0d /src/ship.rs | |
parent | 763653a32e62134a7e394c349d742636b0662a94 (diff) |
-got now a trait which resembles polymorphism for new objects
Diffstat (limited to 'src/ship.rs')
-rw-r--r-- | src/ship.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/ship.rs b/src/ship.rs index f791809..715f019 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,14 +1,33 @@ +use mass::Mass; +extern crate serde_json; + #[derive(Serialize, Deserialize, Debug)] pub struct Ship { - pub name : String, - pub location : (isize, isize, isize), + name : String, + location : (isize, isize, isize), } -impl Ship { - pub fn new(name : &str) -> Ship { +impl Mass for Ship { + fn new(name : &str, location : (isize, isize, isize)) -> Ship { Ship { name : String::from(name), - location : (0,0,0), + location : location, } } + + fn get_name(&self) -> &String { + &self.name + } + + fn get_location(&self) -> (isize, isize, isize) { + self.location + } + + fn give_location(&mut self, location : (isize, isize, isize)) { + self.location = location; + } + + fn serialize(&self) ->String { + serde_json::to_string(self).unwrap() + } } |