From a2b4b4a48521d1751fa9c88cec980f0b4b59427d Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 10 Aug 2022 18:00:04 +0300 Subject: [PATCH] fix(tvix/value): implement PartialOrd/PartialEq for strings Instead of comparing the enum variants (which does not yield useful behaviour), compare &str representations of the string instead. Change-Id: I5e94b5f6c91b4561e1bc7c36d586f3d23c243764 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6112 Tested-by: BuildkiteCI Reviewed-by: eta --- tvix/eval/src/value/string.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs index 47661e03a..1937a3587 100644 --- a/tvix/eval/src/value/string.rs +++ b/tvix/eval/src/value/string.rs @@ -3,7 +3,7 @@ use std::fmt::Display; /// This module implements Nix language strings and their different /// backing implementations. -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Hash, Eq, Ord)] pub enum NixString { Static(&'static str), Heap(String), @@ -18,6 +18,18 @@ impl Display for NixString { } } +impl PartialEq for NixString { + fn eq(&self, other: &Self) -> bool { + self.as_str() == other.as_str() + } +} + +impl PartialOrd for NixString { + fn partial_cmp(&self, other: &Self) -> Option { + self.as_str().partial_cmp(other.as_str()) + } +} + impl From<&'static str> for NixString { fn from(s: &'static str) -> Self { NixString::Static(s)