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.
Trait Implementations§
source§impl From<BuiltinRepr> for Builtin
impl From<BuiltinRepr> for Builtin
source§fn from(value: BuiltinRepr) -> Self
fn from(value: BuiltinRepr) -> Self
Auto Trait Implementations§
impl Freeze for Builtin
impl !RefUnwindSafe for Builtin
impl !Send for Builtin
impl !Sync for Builtin
impl Unpin for Builtin
impl !UnwindSafe for Builtin
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more