summaryrefslogtreecommitdiffstats
path: root/crates/rebel-common/src/types.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-20 16:07:14 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-20 16:12:43 +0200
commit712d356b969540c7f09fad08c141e3c6aadde00f (patch)
tree74bf4e9ad38dea0f42210b4765c8d9c9ef3a16f7 /crates/rebel-common/src/types.rs
parentbb076e62bbfad0386c420b55cd185131460bc345 (diff)
downloadrebel-712d356b969540c7f09fad08c141e3c6aadde00f.tar
rebel-712d356b969540c7f09fad08c141e3c6aadde00f.zip
Introduce TaskIDRef type
A borrowed version of a TaskID, allowing to avoid allocations in some places. Tasks are now stored in a two-level map in Context.
Diffstat (limited to 'crates/rebel-common/src/types.rs')
-rw-r--r--crates/rebel-common/src/types.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/rebel-common/src/types.rs b/crates/rebel-common/src/types.rs
index 2a06275..d3beb70 100644
--- a/crates/rebel-common/src/types.rs
+++ b/crates/rebel-common/src/types.rs
@@ -13,8 +13,29 @@ pub struct TaskID {
pub task: String,
}
+impl TaskID {
+ pub fn as_ref(&self) -> TaskIDRef<'_> {
+ TaskIDRef {
+ recipe: &self.recipe,
+ task: &self.task,
+ }
+ }
+}
+
impl Display for TaskID {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.as_ref().fmt(f)
+ }
+}
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub struct TaskIDRef<'a> {
+ pub recipe: &'a str,
+ pub task: &'a str,
+}
+
+impl<'a> Display for TaskIDRef<'a> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}::{}", self.recipe, self.task)
}
}