pub struct ExternalValueHandle<'s> { /* private fields */ }Expand description
A handle to a Nix external value that retains the ExternalValue*.
nix_get_external is broken in Nix 2.32.7; see the module-level note.
This type stores the ExternalValue* from nix_create_external_value
directly and uses nix_get_external_value_content for downcasting.
Derefs to Value.
Implementations§
Source§impl ExternalValueHandle<'_>
impl ExternalValueHandle<'_>
Sourcepub fn as_external<T: NixExternal>(&self) -> Result<&T>
pub fn as_external<T: NixExternal>(&self) -> Result<&T>
Downcast to a concrete Rust type T.
§Errors
Returns Error::InvalidType if the stored
TypeId does not match T.
Methods from Deref<Target = Value<'s>>§
Sourcepub fn get_attr(&self, key: &str) -> Result<Value<'_>>
pub fn get_attr(&self, key: &str) -> Result<Value<'_>>
Get an attribute by name.
Returns the value associated with the given attribute name.
§Errors
Returns an error if the value is not an attribute set or the key does not exist.
Sourcepub fn attr_keys(&self) -> Result<Vec<String>>
pub fn attr_keys(&self) -> Result<Vec<String>>
Get all attribute keys.
Returns a vector of all attribute names in this attribute set.
§Errors
Returns an error if the value is not an attribute set.
Sourcepub fn has_attr(&self, key: &str) -> Result<bool>
pub fn has_attr(&self, key: &str) -> Result<bool>
Check if an attribute exists.
Returns true if the attribute set contains the given key.
§Errors
Returns an error if the value is not an attribute set.
Sourcepub fn is_list(&self) -> bool
pub fn is_list(&self) -> bool
Check if this value is a list.
§Example
use std::sync::Arc;
use nix_bindings::{Context, EvalStateBuilder, Store};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = Arc::new(Context::new()?);
let store = Arc::new(Store::open(&ctx, None)?);
let state = EvalStateBuilder::new(&store)?.build()?;
let list = state.eval_from_string("[1 2 3]", "<eval>")?;
assert!(list.is_list());
Ok(())
}Sourcepub fn list_get(&self, idx: usize) -> Result<Value<'_>>
pub fn list_get(&self, idx: usize) -> Result<Value<'_>>
Get an element from this list by index.
§Arguments
idx- The index of the element to retrieve (0-based)
§Errors
Returns an error if this value is not a list or the index is out of bounds.
§Example
let list = state.eval_from_string("[1 2 3]", "<eval>")?;
let first = list.list_get(0)?;
assert_eq!(first.as_int()?, 1);Sourcepub fn list_iter(&self) -> Result<ListIterator<'_>>
pub fn list_iter(&self) -> Result<ListIterator<'_>>
Create an iterator over the elements of this list.
§Errors
Returns an error if this value is not a list.
Sourcepub fn value_type(&self) -> ValueType
pub fn value_type(&self) -> ValueType
Get the type of this value.
Does not force; a lazy attribute or list element reports as
ValueType::Thunk until forced. Use force or any
as_* accessor (which force implicitly) first.
Sourcepub fn type_name(&self) -> String
pub fn type_name(&self) -> String
Get the Nix type name of this value as reported by the C API.
Wraps nix_get_typename. Returns Nix’s source-of-truth string (e.g.
"int", "thunk", "lambda"). Falls back to the local
[ValueType::to_string] if the C call returns null.
Sourcepub fn as_int(&self) -> Result<i64>
pub fn as_int(&self) -> Result<i64>
Convert this value to an integer. Forces the value first.
§Errors
Returns an error if forcing fails or the resolved value is not an integer.
Sourcepub fn as_float(&self) -> Result<f64>
pub fn as_float(&self) -> Result<f64>
Convert this value to a float. Forces the value first.
§Errors
Returns an error if forcing fails or the resolved value is not a float.
Sourcepub fn as_bool(&self) -> Result<bool>
pub fn as_bool(&self) -> Result<bool>
Convert this value to a boolean. Forces the value first.
§Errors
Returns an error if forcing fails or the resolved value is not a boolean.
Sourcepub fn as_string(&self) -> Result<String>
pub fn as_string(&self) -> Result<String>
Convert this value to a string.
Realises any string context. Forces the value first.
§Errors
Returns an error if forcing fails or the value is not a string.
Sourcepub fn as_path(&self) -> Result<PathBuf>
pub fn as_path(&self) -> Result<PathBuf>
Convert this value to a filesystem path. Forces the value first.
§Errors
Returns an error if forcing fails or the value is not a path.
Sourcepub fn call(&self, arg: &Value<'_>) -> Result<Value<'_>>
pub fn call(&self, arg: &Value<'_>) -> Result<Value<'_>>
Call this value as a function with a single argument.
§Errors
Returns an error if this value is not a function or the call fails.
Sourcepub fn call_multi(&self, args: &[&Value<'_>]) -> Result<Value<'_>>
pub fn call_multi(&self, args: &[&Value<'_>]) -> Result<Value<'_>>
Call this value as a curried function with multiple arguments.
§Errors
Returns an error if this value is not a function or the call fails.
Sourcepub fn to_nix_string(&self) -> Result<String>
pub fn to_nix_string(&self) -> Result<String>
Format this value as Nix syntax.
Forces the value first and recursively renders attribute sets and
lists. Functions, thunks, and external values render as opaque
placeholders (<lambda>, <thunk>, <external>) the same way
nix-instantiate --eval does.
§Errors
Returns an error if forcing fails or any nested value cannot be rendered.