fix(tvix/value): ensure only string values of NixString are hashed

Change-Id: I1b97cf5a9e4e235fac72a507de49a8df508bcaa1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6138
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-10 20:42:54 +03:00 committed by tazjin
parent fb3d024d75
commit 58db7e3a65

View file

@ -1,9 +1,10 @@
use std::hash::Hash;
use std::{borrow::Cow, fmt::Display};
/// This module implements Nix language strings and their different
/// backing implementations.
#[derive(Clone, Debug, Hash, Eq, Ord)]
#[derive(Clone, Debug, Eq, Ord)]
pub enum NixString {
Static(&'static str),
Heap(String),
@ -33,6 +34,12 @@ impl From<String> for NixString {
}
}
impl Hash for NixString {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.as_str().hash(state)
}
}
impl NixString {
pub const NAME: Self = NixString::Static("name");
pub const VALUE: Self = NixString::Static("value");