feat(tvix/value): add some necessary helpers for strings
Deriving Ord/Eq is required for the ordered BTreeMaps. Once interning is implemented this will require some extra magic for the sort order, but that's fine. Change-Id: I0c654648eb3609a4a01d84868c25f43a4d35bc2e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6089 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
parent
865717a8db
commit
e24248df3b
2 changed files with 14 additions and 4 deletions
|
@ -7,8 +7,8 @@ mod attrs;
|
|||
mod string;
|
||||
|
||||
use crate::errors::{Error, EvalResult};
|
||||
use attrs::NixAttrs;
|
||||
use string::NixString;
|
||||
pub use attrs::NixAttrs;
|
||||
pub use string::NixString;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Value {
|
||||
|
@ -49,6 +49,16 @@ impl Value {
|
|||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_string(self) -> EvalResult<NixString> {
|
||||
match self {
|
||||
Value::String(s) => Ok(s),
|
||||
other => Err(Error::TypeError {
|
||||
expected: "string",
|
||||
actual: other.type_of(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Value {
|
||||
|
|
|
@ -3,8 +3,8 @@ use std::fmt::Display;
|
|||
/// This module implements Nix language strings and their different
|
||||
/// backing implementations.
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
pub struct NixString(String);
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct NixString(pub String);
|
||||
|
||||
impl Display for NixString {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
|
|
Loading…
Reference in a new issue