pub struct PrimOpRet<'a> { /* private fields */ }Expand description
The writable return-value slot provided to a primop closure.
Exactly one set_* method must be called before returning Ok(()).
The trampoline verifies this at runtime and synthesises a Nix
EvalError when the closure returned Ok(()) without writing the
slot.
Implementations§
Source§impl<'a> PrimOpRet<'a>
impl<'a> PrimOpRet<'a>
Sourcepub fn set_string(&mut self, s: &str) -> Result<()>
pub fn set_string(&mut self, s: &str) -> Result<()>
Write a string result.
§Errors
Returns an error if s contains an interior NUL byte or the write
fails.
Sourcepub fn set_path(&mut self, p: &str) -> Result<()>
pub fn set_path(&mut self, p: &str) -> Result<()>
Write a path result.
The path string is interpreted by Nix the same way a path literal
would be (e.g. it can be an absolute filesystem path or a store path).
§Pure Evaluation
This calls nix_init_path_string, which the Nix evaluator rejects for
absolute paths when running with --pure-eval. It returns
Error::EvalError in that case. If the path is a store path your primop
already added to the store, use set_store_path
(requires the shim feature) instead; it registers the path with the
evaluator’s allowlist so the value is usable in pure mode.
§Errors
Returns an error if p contains an interior NUL byte, the write fails,
or Nix is running in pure evaluation mode and p is an absolute path.
Sourcepub fn set_store_path_typed(
&mut self,
store: &Store,
path: &StorePath,
) -> Result<()>
pub fn set_store_path_typed( &mut self, store: &Store, path: &StorePath, ) -> Result<()>
Type-safe variant of set_store_path.
Takes a parsed StorePath instead of a raw
string. Eliminates the chance of passing a non-store-path string that
would be rejected by Nix’s parser at the C++ level. Uses
Store::print_path to render the
path back to its canonical form.
Requires the shim and store features.
§Errors
Returns an error if rendering or the write fails.
Sourcepub fn set_store_path(&mut self, p: &str) -> Result<()>
pub fn set_store_path(&mut self, p: &str) -> Result<()>
Write a store path as a Nix path value, registering it as accessible in the evaluator’s allowlist first.
In pure evaluation mode (--pure-eval) Nix wraps the filesystem in an
AllowListSourceAccessor that rejects any path not explicitly permitted.
This method calls EvalState::allowPath before writing the value,
mirroring what Nix’s own fetch builtins do after adding a path to the
store. The resulting path value is usable (e.g. as src in a
derivation) without triggering the access restriction.
The caller must ensure p is a canonical store path that already exists
in the store.
§Errors
Returns an error if p contains an interior NUL byte, is not a valid
store path, or the write fails.
Sourcepub fn set_attrs(&mut self, pairs: &[(&str, &PrimOpValue<'_>)]) -> Result<()>
pub fn set_attrs(&mut self, pairs: &[(&str, &PrimOpValue<'_>)]) -> Result<()>
Write an attribute set result.
Builds an attribute set from the given key-value pairs and writes it
into the return slot. Each value is a PrimOpValue obtained from a
primop argument or created via the make_* methods on this struct.
§Errors
Returns an error if construction fails.
Sourcepub fn set_list(&mut self, items: &[&PrimOpValue<'_>]) -> Result<()>
pub fn set_list(&mut self, items: &[&PrimOpValue<'_>]) -> Result<()>
Write a list result.
Builds a list from the given values and writes it into the return
slot. Each value is a PrimOpValue obtained from a primop
argument or created via the make_* methods on this struct.
§Errors
Returns an error if construction fails.
Sourcepub fn make_int(&self, i: i64) -> Result<PrimOpValue<'a>>
pub fn make_int(&self, i: i64) -> Result<PrimOpValue<'a>>
Allocate and initialise an integer PrimOpValue.
§Errors
Returns an error if allocation or initialisation fails.
Sourcepub fn make_float(&self, f: f64) -> Result<PrimOpValue<'a>>
pub fn make_float(&self, f: f64) -> Result<PrimOpValue<'a>>
Allocate and initialise a float PrimOpValue.
§Errors
Returns an error if allocation or initialisation fails.
Sourcepub fn make_bool(&self, b: bool) -> Result<PrimOpValue<'a>>
pub fn make_bool(&self, b: bool) -> Result<PrimOpValue<'a>>
Allocate and initialise a boolean PrimOpValue.
§Errors
Returns an error if allocation or initialisation fails.
Sourcepub fn make_null(&self) -> Result<PrimOpValue<'a>>
pub fn make_null(&self) -> Result<PrimOpValue<'a>>
Allocate and initialise a null PrimOpValue.
§Errors
Returns an error if allocation or initialisation fails.
Sourcepub fn make_string(&self, s: &str) -> Result<PrimOpValue<'a>>
pub fn make_string(&self, s: &str) -> Result<PrimOpValue<'a>>
Allocate and initialise a string PrimOpValue.
§Errors
Returns an error if allocation, string conversion, or initialisation fails.
Sourcepub fn make_path(&self, p: &str) -> Result<PrimOpValue<'a>>
pub fn make_path(&self, p: &str) -> Result<PrimOpValue<'a>>
Allocate and initialise a path PrimOpValue.
§Pure Evaluation
This calls nix_init_path_string, which the Nix evaluator rejects for
absolute paths when running with --pure-eval. If the path is a store
path your primop already added to the store, use
make_store_path (requires the shim feature)
instead; it registers the path with the evaluator’s allowlist so the
value is usable in pure mode.
§Errors
Returns an error if allocation, string conversion, or initialisation
fails, or Nix is running in pure evaluation mode and p is absolute.
Sourcepub fn make_store_path_typed(
&self,
store: &Store,
path: &StorePath,
) -> Result<PrimOpValue<'a>>
pub fn make_store_path_typed( &self, store: &Store, path: &StorePath, ) -> Result<PrimOpValue<'a>>
Type-safe variant of make_store_path.
Takes a parsed StorePath and renders it
to a canonical string via
Store::print_path.
Requires the shim and store features.
§Errors
Returns an error if rendering or initialisation fails.
Sourcepub fn make_store_path(&self, p: &str) -> Result<PrimOpValue<'a>>
pub fn make_store_path(&self, p: &str) -> Result<PrimOpValue<'a>>
Allocate and initialise a store path PrimOpValue, registering it as
accessible in the evaluator’s allowlist first.
Equivalent to set_store_path but allocates and
returns a new PrimOpValue instead of writing into the return slot.
See set_store_path for the full description of
the allowlist mechanism.
The caller must ensure p is a canonical store path that already exists
in the store.
§Errors
Returns an error if allocation, string conversion, p is not a valid
store path, or initialisation fails.