From fa2d250d1a65ba3bf8522fdbbe72dca21fa7ee66 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 10 Aug 2022 20:59:56 +0300 Subject: fix(tvix/value): explicitly delegate `Ord` to &str representation I assumed that `Ord` is a marker trait like `Eq`, but it actually has a member. Without this ordering was incoherent. Change-Id: Id37cbdf333daf748d29b85243046c7e061b1ce29 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6139 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/value/string.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tvix/eval/src/value/string.rs') diff --git a/tvix/eval/src/value/string.rs b/tvix/eval/src/value/string.rs index f9178ca7f4bb..3816e89cd1b1 100644 --- a/tvix/eval/src/value/string.rs +++ b/tvix/eval/src/value/string.rs @@ -4,7 +4,7 @@ use std::{borrow::Cow, fmt::Display}; /// This module implements Nix language strings and their different /// backing implementations. -#[derive(Clone, Debug, Eq, Ord)] +#[derive(Clone, Debug)] pub enum NixString { Static(&'static str), Heap(String), @@ -16,12 +16,20 @@ impl PartialEq for NixString { } } +impl Eq for NixString {} + impl PartialOrd for NixString { fn partial_cmp(&self, other: &Self) -> Option { self.as_str().partial_cmp(other.as_str()) } } +impl Ord for NixString { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.as_str().cmp(other.as_str()) + } +} + impl From<&'static str> for NixString { fn from(s: &'static str) -> Self { NixString::Static(s) -- cgit 1.4.1