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 <tvl@eta.st>
This commit is contained in:
parent
6dc9ca5723
commit
a2b4b4a485
1 changed files with 13 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue