Skip to main content

PrimOpRet

Struct PrimOpRet 

Source
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>

Source

pub fn set_int(&mut self, i: i64) -> Result<()>

Write an integer result.

§Errors

Returns an error if the write fails.

Source

pub fn set_float(&mut self, f: f64) -> Result<()>

Write a float result.

§Errors

Returns an error if the write fails.

Source

pub fn set_bool(&mut self, b: bool) -> Result<()>

Write a boolean result.

§Errors

Returns an error if the write fails.

Source

pub fn set_null(&mut self) -> Result<()>

Write a null result.

§Errors

Returns an error if the write fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub unsafe fn copy_from_raw(&mut self, src: *mut nix_value) -> Result<()>

Copy the value pointed to by src into the return slot.

This is useful when the result is an existing Value that should be forwarded as-is.

§Safety

src must be a valid, non-null *mut nix_value that remains live for the duration of the call.

§Errors

Returns an error if the copy fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn make_null(&self) -> Result<PrimOpValue<'a>>

Allocate and initialise a null PrimOpValue.

§Errors

Returns an error if allocation or initialisation fails.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a> Freeze for PrimOpRet<'a>

§

impl<'a> RefUnwindSafe for PrimOpRet<'a>

§

impl<'a> !Send for PrimOpRet<'a>

§

impl<'a> !Sync for PrimOpRet<'a>

§

impl<'a> Unpin for PrimOpRet<'a>

§

impl<'a> UnsafeUnpin for PrimOpRet<'a>

§

impl<'a> !UnwindSafe for PrimOpRet<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.