feat: Add EvalState.require_attrs_names (sorted)
(cherry picked from commit 0b1aca5a1ee7136e76a201477643cfc3acbf2676)
This commit is contained in:
parent
237a2281c1
commit
76b92a577d
1 changed files with 12 additions and 0 deletions
|
|
@ -208,8 +208,20 @@ impl EvalState {
|
||||||
}
|
}
|
||||||
unsafe { check_call!(raw::get_int(&mut self.context, v.raw_ptr())) }
|
unsafe { check_call!(raw::get_int(&mut self.context, v.raw_ptr())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate, and require that the value is an attrset.
|
/// Evaluate, and require that the value is an attrset.
|
||||||
/// Returns a list of the keys in the attrset.
|
/// Returns a list of the keys in the attrset.
|
||||||
|
///
|
||||||
|
/// NOTE: this currently implements its own sorting, which probably matches Nix's implementation, but is not guaranteed.
|
||||||
|
pub fn require_attrs_names(&mut self, v: &Value) -> Result<Vec<String>> {
|
||||||
|
self.require_attrs_names_unsorted(v).map(|mut v| {
|
||||||
|
v.sort();
|
||||||
|
v
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// For when [require_attrs_names] isn't fast enough.
|
||||||
|
/// Only use when it's ok that the keys are returned in an arbitrary order.
|
||||||
pub fn require_attrs_names_unsorted(&mut self, v: &Value) -> Result<Vec<String>> {
|
pub fn require_attrs_names_unsorted(&mut self, v: &Value) -> Result<Vec<String>> {
|
||||||
let t = self.value_type(v)?;
|
let t = self.value_type(v)?;
|
||||||
if t != ValueType::AttrSet {
|
if t != ValueType::AttrSet {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue