diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-10T15·00+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-08-24T18·19+0000 |
commit | a2b4b4a48521d1751fa9c88cec980f0b4b59427d (patch) | |
tree | e2870f6db85d363acc42ce07cecca2dcd7792917 /tvix | |
parent | 6dc9ca5723ee46ade3ad3618ae780ec88ae884e2 (diff) |
fix(tvix/value): implement PartialOrd/PartialEq for strings r/4458
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 <tvl@eta.st>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/eval/src/value/string.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs index 47661e03add4..1937a35870d3 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<std::cmp::Ordering> { + self.as_str().partial_cmp(other.as_str()) + } +} + impl From<&'static str> for NixString { fn from(s: &'static str) -> Self { NixString::Static(s) |