doc: EvalState::eval_from_string
(cherry picked from commit b1de918abddc8166973c956ec77d597dae92f928)
This commit is contained in:
parent
fe4d62d083
commit
d89fb1803f
1 changed files with 19 additions and 0 deletions
|
|
@ -88,6 +88,25 @@ impl EvalState {
|
|||
pub fn store(&self) -> &Store {
|
||||
&self.store
|
||||
}
|
||||
/// Parses and evaluates a Nix expression `expr`.
|
||||
///
|
||||
/// Expressions can contain relative paths such as `./.` that are resolved relative to the given `path`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use nix_expr::eval_state::EvalState;
|
||||
/// use nix_store::store::Store;
|
||||
/// use nix_expr::value::Value;
|
||||
///
|
||||
/// # fn main() -> anyhow::Result<()> {
|
||||
/// # let es = EvalState::new(Store::open("auto", [])?, [])?;
|
||||
/// let v: Value = es.eval_from_string("42", ".")?;
|
||||
/// assert_eq!(es.require_int(&v)?, 42);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[doc(alias = "nix_expr_eval_from_string")]
|
||||
pub fn eval_from_string(&self, expr: &str, path: &str) -> Result<Value> {
|
||||
let expr_ptr =
|
||||
CString::new(expr).with_context(|| "eval_from_string: expr contains null byte")?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue