pub struct Builtin(Box<BuiltinRepr>);
Expand description
Represents a single built-in function which directly executes Rust code that operates on a Nix value.
Builtins are the only functions in Nix that have varying arities
(for example, hasAttr
has an arity of 2, but isAttrs
an arity
of 1). To facilitate this generically, builtins expect to be
called with a vector of Nix values corresponding to their
arguments in order.
Partially applied builtins act similar to closures in that they “capture” the partially applied arguments, and are treated specially when printing their representation etc.
Tuple Fields§
§0: Box<BuiltinRepr>
Implementations§
source§impl Builtin
impl Builtin
pub fn new<F: BuiltinGen + 'static>( name: &'static str, documentation: Option<&'static str>, arg_count: usize, func: F, ) -> Self
pub fn name(&self) -> &'static str
pub fn documentation(&self) -> Option<&'static str>
sourcepub fn apply_arg(&mut self, arg: Value)
pub fn apply_arg(&mut self, arg: Value)
Apply an additional argument to the builtin.
After this, Builtin::call
must be called, otherwise it may leave
the builtin in an incorrect state.
sourcepub fn call(self) -> BuiltinResult
pub fn call(self) -> BuiltinResult
Attempt to call a builtin, which will produce a generator if it is fully applied or return the builtin if it is partially applied.