diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-07T23·55+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-08-12T14·09+0000 |
commit | d431f43f5fbb0c8eaa23fd082ddb8839cdc0f642 (patch) | |
tree | 3f9d016912095141f4ab4e36f556cfbbdd47b964 /tvix/eval/src/value.rs | |
parent | ded0fb9e21d4b8794fa668941474b26d45ef6f3d (diff) |
feat(tvix/eval): implement boolean inversion operator r/4415
Change-Id: Icb1d449fdee4d67b5f1eefdbc01baa1584ea0a67 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6079 Tested-by: BuildkiteCI Autosubmit: tazjin <tazjin@tvl.su> Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix/eval/src/value.rs')
-rw-r--r-- | tvix/eval/src/value.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/value.rs b/tvix/eval/src/value.rs index cbfff55b49e1..842d561d67a6 100644 --- a/tvix/eval/src/value.rs +++ b/tvix/eval/src/value.rs @@ -1,6 +1,8 @@ //! This module implements the backing representation of runtime //! values in the Nix language. +use crate::errors::{Error, EvalResult}; + #[derive(Clone, Copy, Debug, PartialEq)] pub enum Value { Null, @@ -26,6 +28,16 @@ impl Value { Value::Float(_) => "float", } } + + pub fn as_bool(self) -> EvalResult<bool> { + match self { + Value::Bool(b) => Ok(b), + other => Err(Error::TypeError { + expected: "bool", + actual: other.type_of(), + }), + } + } } #[derive(Clone, Copy, Debug, PartialEq)] |