From 7798ebba1d8762e8b4c6eaf1efcd610fa030375a Mon Sep 17 00:00:00 2001 From: tom barrett Date: Fri, 23 Feb 2018 01:10:14 -0600 Subject: -found way to downcast and created new struct --- src/astroid.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/astroid.rs (limited to 'src/astroid.rs') diff --git a/src/astroid.rs b/src/astroid.rs new file mode 100644 index 0000000..dd47123 --- /dev/null +++ b/src/astroid.rs @@ -0,0 +1,33 @@ +use mass::Mass; +extern crate serde_json; + +#[derive(Serialize, Deserialize, Debug)] +pub struct Astroid { + name : String, + location : (isize, isize, isize), +} + +impl Mass for Astroid { + fn new(name : &str, location : (isize, isize, isize)) -> Astroid { + Astroid { + name : String::from(name), + location : location, + } + } + + fn name(&self) -> &String { + &self.name + } + + fn location(&self) -> (isize, isize, isize) { + self.location + } + + fn set_location(&mut self, location : (isize, isize, isize)) { + self.location = location; + } + + fn serialize(&self) ->String { + serde_json::to_string(self).unwrap() + } +} -- cgit v1.2.3