From 9521df708f92a237090b1b17ec969b319c4d00fe Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 29 Jul 2023 19:33:00 +0200 Subject: feat(nix-compat/store_path): implement PartialOrd and Ord 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 Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- tvix/nix-compat/src/store_path/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tvix/nix-compat/src/store_path/mod.rs') 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 { + 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; -- cgit 1.4.1