aboutsummaryrefslogtreecommitdiff
path: root/src/star.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/star.rs')
-rw-r--r--src/star.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/star.rs b/src/star.rs
index dad8789..53c9124 100644
--- a/src/star.rs
+++ b/src/star.rs
@@ -96,6 +96,17 @@ impl Star {
}
}
+ pub fn find_planet(&mut self, uuid: String) -> Result<Planet, Error> {
+ let inhab = self.inhabitants()?;
+
+ for i in inhab {
+ if i.uuid == uuid {
+ return Ok(i);
+ }
+ }
+ Err(Error::Other(String::from("Not found")))
+ }
+
/// Creates a new Planet orbiting the Star, taking care of everything needed to make the VM run
/// fine
///
@@ -237,4 +248,13 @@ mod test {
assert_eq!(h.inhabitants().unwrap().len(), 1);
}
+ #[test]
+ fn get_planet() {
+ let mut s: Star = Star::new("test:///default".to_string()).unwrap();
+
+ let t = s.inhabitants().unwrap()[0].clone();
+
+ assert_eq!(s.find_planet(t.uuid.clone()).unwrap(), t);
+ }
+
}