feat(tvix/eval): add helper for selecting required attributes

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>
This commit is contained in:
Vincent Ambo 2022-11-05 16:51:37 +03:00 committed by clbot
parent e816d3a9dc
commit cf82a545eb

View file

@ -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)
}