diff options
author | Vincent Ambo <mail@tazj.in> | 2022-11-05T13·51+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-11-08T12·33+0000 |
commit | cf82a545eb68b57ceb940ebd467e669ca19d7483 (patch) | |
tree | 6b118663b332a42f7f803ad09c9e91c40d9cb2b5 /tvix/eval | |
parent | e816d3a9dce30dc49ca830d705ccb6e5bfd569e8 (diff) |
feat(tvix/eval): add helper for selecting required attributes r/5262
Change-Id: Idd4ae78ef55891d89b72b5c2f3afc8b697b4b26e Reviewed-on: https://cl.tvl.fyi/c/depot/+/7189 Reviewed-by: grfn <grfn@gws.fyi> Reviewed-by: Adam Joseph <adam@westernsemico.com> Tested-by: BuildkiteCI Autosubmit: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval')
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index 59e477db4acf..d8e3001f4a18 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -217,6 +217,13 @@ impl NixAttrs { self.0.select(key) } + /// Select a required value from an attribute set by key, return + /// an `AttributeNotFound` error if it is missing. + pub fn select_required(&self, key: &str) -> Result<&Value, ErrorKind> { + self.select(key) + .ok_or_else(|| ErrorKind::AttributeNotFound { name: key.into() }) + } + pub fn contains(&self, key: &str) -> bool { self.0.contains(key) } |