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:
parent
e816d3a9dc
commit
cf82a545eb
1 changed files with 7 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue