Skip to main content

NixValueOps

Trait NixValueOps 

Source
pub trait NixValueOps: NixValueRaw {
    // Provided methods
    fn value_type(&self) -> ValueType { ... }
    fn force(&self) -> Result<()> { ... }
    fn as_int(&self) -> Result<i64> { ... }
    fn as_float(&self) -> Result<f64> { ... }
    fn as_bool(&self) -> Result<bool> { ... }
    fn as_string(&self) -> Result<String> { ... }
    fn as_path(&self) -> Result<String> { ... }
}
Expand description

Read access to a Nix value.

Implemented by Value, primop::PrimOpArg, and primop::PrimOpValue. All accessors force the value first, mirroring nix-instantiate-style semantics: a lazy attribute that resolves to an int is reported as an int, not a thunk.

Provided Methods§

Source

fn value_type(&self) -> ValueType

Return the ValueType of this value.

Does not force; an unforced thunk reports as ValueType::Thunk. Use force (or any as_* accessor) to resolve first.

Source

fn force(&self) -> Result<()>

Force evaluation (resolves thunks).

§Errors

Returns an error if evaluation fails.

Source

fn as_int(&self) -> Result<i64>

Extract as an integer. Forces the value first.

§Errors

Returns an error if forcing fails or the resolved value is not an integer.

Source

fn as_float(&self) -> Result<f64>

Extract as a float. Forces the value first.

§Errors

Returns an error if forcing fails or the resolved value is not a float.

Source

fn as_bool(&self) -> Result<bool>

Extract as a boolean. Forces the value first.

§Errors

Returns an error if forcing fails or the resolved value is not a boolean.

Source

fn as_string(&self) -> Result<String>

Extract as a UTF-8 string, realising any string context. Forces the value first.

§Errors

Returns an error if forcing fails, the resolved value is not a string, or the string contains invalid UTF-8.

Source

fn as_path(&self) -> Result<String>

Extract as a filesystem-path string. Forces the value first.

§Errors

Returns an error if forcing fails, the resolved value is not a path, or the path contains invalid UTF-8.

Implementors§

Source§

impl<T: NixValueRaw> NixValueOps for T