summaryrefslogtreecommitdiffstats
path: root/crates/common/src/string_hash.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-10-24 22:40:08 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-10-24 23:58:03 +0200
commita1a185370da27f2cc3df84d3a8d7141f9ce7db16 (patch)
tree6904f6f0549e89d160cbe635713e2864df25c21a /crates/common/src/string_hash.rs
parent524985f9449eb2f3a1d01b5f88dc74123d40c43a (diff)
downloadrebel-a1a185370da27f2cc3df84d3a8d7141f9ce7db16.tar
rebel-a1a185370da27f2cc3df84d3a8d7141f9ce7db16.zip
Split defintions used by both runner and executor into separate crate
Also get rid of the Runner trait - different runner implementations do not make sense with our current design.
Diffstat (limited to 'crates/common/src/string_hash.rs')
-rw-r--r--crates/common/src/string_hash.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/crates/common/src/string_hash.rs b/crates/common/src/string_hash.rs
new file mode 100644
index 0000000..a2b00db
--- /dev/null
+++ b/crates/common/src/string_hash.rs
@@ -0,0 +1,53 @@
+use std::fmt::Display;
+
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Copy, PartialEq, Eq, Hash)]
+pub struct StringHash(pub [u8; 32]);
+
+impl Display for StringHash {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(&hex::encode(self.0))
+ }
+}
+
+impl std::fmt::Debug for StringHash {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "\"{}\"", self)
+ }
+}
+
+impl Serialize for StringHash {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: serde::Serializer,
+ {
+ hex::serialize(self.0, serializer)
+ }
+}
+impl<'de> Deserialize<'de> for StringHash {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: serde::Deserializer<'de>,
+ {
+ Ok(StringHash(hex::deserialize(deserializer)?))
+ }
+}
+
+macro_rules! stringhash_newtype {
+ ($id:ident) => {
+ #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
+ pub struct $id(pub StringHash);
+
+ impl Display for $id {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.0.fmt(f)
+ }
+ }
+ };
+}
+
+stringhash_newtype!(InputHash);
+stringhash_newtype!(DependencyHash);
+stringhash_newtype!(LayerHash);
+stringhash_newtype!(ArchiveHash);