aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-06-09 09:42:16 -0400
committerCara Salter <cara@devcara.com>2022-06-09 09:42:16 -0400
commit5b9b4502f3c020423f257a68c1badb077aee4133 (patch)
treecdd8dc5c3f16d015c95e9c4931a4453ad4fb97f8
parentd674951ce8cb5b41afe68bbeefcd9ee585125ab9 (diff)
downloadsolarlib-5b9b4502f3c020423f257a68c1badb077aee4133.tar.gz
solarlib-5b9b4502f3c020423f257a68c1badb077aee4133.zip
star: Allow for getting planets based on UUID
-rw-r--r--Cargo.toml2
-rw-r--r--src/star.rs20
2 files changed, 21 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 3f0496f..2fd5fb6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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);
+ }
+
}