diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/star.rs | 20 |
2 files changed, 21 insertions, 1 deletions
@@ -1,6 +1,6 @@ [package] name = "solarlib" -version = "1.3.0" +version = "1.3.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 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); + } + } |