From 5b9b4502f3c020423f257a68c1badb077aee4133 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Thu, 9 Jun 2022 09:42:16 -0400 Subject: star: Allow for getting planets based on UUID --- src/star.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/star.rs') 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 { + 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); + } + } -- cgit v1.2.3