diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-09T13·52+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-08-13T11·50+0000 |
commit | e24248df3bba6c4df2028a7eb9e68660b1d3b4e7 (patch) | |
tree | 658db19ee9036e188f02b6b89b9514ffcfdffe8d /tvix/eval/src/value/mod.rs | |
parent | 865717a8dbef9f89f2c32d0c86d970f3c21dbd9f (diff) |
feat(tvix/value): add some necessary helpers for strings r/4425
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>
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-rw-r--r-- | tvix/eval/src/value/mod.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index ea0c89e6b6c4..56f8620d3a58 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -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 { |