about summary refs log tree commit diff
path: root/tvix/nix-compat/src/store_path/mod.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-07-29T17·33+0200
committerclbot <clbot@tvl.fyi>2023-07-31T20·29+0000
commit9521df708f92a237090b1b17ec969b319c4d00fe (patch)
tree4cfc5f777ca909a34408b252f79b7b08ff5ce568 /tvix/nix-compat/src/store_path/mod.rs
parent0dea3086f5ed15191d01e499d55e6edfa73805ee (diff)
feat(nix-compat/store_path): implement PartialOrd and Ord r/6448
This allows sorting Store Paths. We delegate the sorting business to the
PartialOrd, Ord impls for our digest fields only, as two StorePaths with
the same digest, but different names can't exist.

Change-Id: I5f81631e5f5063893b316c63a240c5266b7e5bad
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8988
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/nix-compat/src/store_path/mod.rs')
-rw-r--r--tvix/nix-compat/src/store_path/mod.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs
index 6372b39d75..fef57aa7ff 100644
--- a/tvix/nix-compat/src/store_path/mod.rs
+++ b/tvix/nix-compat/src/store_path/mod.rs
@@ -51,6 +51,18 @@ pub struct StorePath {
     pub name: String,
 }
 
+impl PartialOrd for StorePath {
+    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+        self.digest.partial_cmp(&other.digest)
+    }
+}
+
+impl Ord for StorePath {
+    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+        self.digest.cmp(&other.digest)
+    }
+}
+
 impl FromStr for StorePath {
     type Err = Error;