diff options
author | Cara Salter <cara@devcara.com> | 2022-06-09 09:42:16 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-06-09 09:42:16 -0400 |
commit | 5b9b4502f3c020423f257a68c1badb077aee4133 (patch) | |
tree | cdd8dc5c3f16d015c95e9c4931a4453ad4fb97f8 /src | |
parent | d674951ce8cb5b41afe68bbeefcd9ee585125ab9 (diff) | |
download | solarlib-5b9b4502f3c020423f257a68c1badb077aee4133.tar.gz solarlib-5b9b4502f3c020423f257a68c1badb077aee4133.zip |
star: Allow for getting planets based on UUID
Diffstat (limited to 'src')
-rw-r--r-- | src/star.rs | 20 |
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); + } + } |