chore(tvix/eval): provide 'static references to "name"/"value"

These static strings show up a bunch when dealing with the internals
of attribute sets, and having them available as static references is
required.

Due to the way const expressions are evaluated, taking a reference to
the existing NixString::NAME / NixString::VALUE items does not work
and the references themselves need to be const-evaluated.

Change-Id: If6e75847af978118a3b266fe6a3242321722434d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6366
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-31 04:27:09 +03:00 committed by tazjin
parent 80713f207e
commit 7d5dca7ba3

View file

@ -60,7 +60,10 @@ impl Hash for NixString {
impl NixString { impl NixString {
pub const NAME: Self = NixString(StringRepr::Smol(SmolStr::new_inline("name"))); pub const NAME: Self = NixString(StringRepr::Smol(SmolStr::new_inline("name")));
pub const NAME_REF: &'static Self = &Self::NAME;
pub const VALUE: Self = NixString(StringRepr::Smol(SmolStr::new_inline("value"))); pub const VALUE: Self = NixString(StringRepr::Smol(SmolStr::new_inline("value")));
pub const VALUE_REF: &'static Self = &Self::VALUE;
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {
match &self.0 { match &self.0 {