Skip to main content

NixExpr

Enum NixExpr 

Source
pub enum NixExpr {
Show 23 variants Int(i64), Float(f64), Bool(bool), Str(String), Path(String), Null, List(Vec<NixExpr>), AttrSet(Vec<NixAttr>), Rec(Vec<NixAttr>), With(Box<NixExpr>, Box<NixExpr>), Let(Vec<NixLetBinding>, Box<NixExpr>), If(Box<NixExpr>, Box<NixExpr>, Box<NixExpr>), Lambda(Box<NixFunction>), Apply(Box<NixExpr>, Box<NixExpr>), Select(Box<NixExpr>, String, Option<Box<NixExpr>>), Assert(Box<NixExpr>, Box<NixExpr>), Var(String), Inherit(Option<Box<NixExpr>>, Vec<String>), Antiquote(String, Box<NixExpr>, String), Multiline(String), UnOp(String, Box<NixExpr>), BinOp(String, Box<NixExpr>, Box<NixExpr>), Import(Box<NixExpr>),
}
Expand description

Nix expression AST.

Variants§

§

Int(i64)

Integer literal: 42

§

Float(f64)

Float literal: 3.14

§

Bool(bool)

Boolean literal: true / false

§

Str(String)

String literal: "hello, world"

§

Path(String)

Path literal: ./path/to/file or /absolute/path

§

Null

null

§

List(Vec<NixExpr>)

List literal: [ e1 e2 e3 ]

§

AttrSet(Vec<NixAttr>)

Attribute set: { a = 1; b = 2; }

§

Rec(Vec<NixAttr>)

Recursive attribute set: rec { a = 1; b = a + 1; }

§

With(Box<NixExpr>, Box<NixExpr>)

with expr; body — bring all attrs of expr into scope

§

Let(Vec<NixLetBinding>, Box<NixExpr>)

let bindings in body

§

If(Box<NixExpr>, Box<NixExpr>, Box<NixExpr>)

if cond then t else f

§

Lambda(Box<NixFunction>)

Function abstraction: pat: body

§

Apply(Box<NixExpr>, Box<NixExpr>)

Function application: f arg

§

Select(Box<NixExpr>, String, Option<Box<NixExpr>>)

Attribute selection: e.attr or e.attr or default

§

Assert(Box<NixExpr>, Box<NixExpr>)

assert cond; body

§

Var(String)

Variable reference: pkgs, lib.mkOption, etc.

§

Inherit(Option<Box<NixExpr>>, Vec<String>)

Inherit expression inside a set: inherit (src) a b;

§

Antiquote(String, Box<NixExpr>, String)

String interpolation antiquotation: "prefix ${expr} suffix"

§

Multiline(String)

Multi-line (indented) string: '' ... ''

§

UnOp(String, Box<NixExpr>)

Unary operator: !b, -n

§

BinOp(String, Box<NixExpr>, Box<NixExpr>)

Binary operator: a + b, a // b, a ++ b, a == b, etc.

§

Import(Box<NixExpr>)

builtins.import or any builtins.* call

Implementations§

Source§

impl NixExpr

Source

pub fn emit(&self, indent: usize) -> String

Emit this expression as a Nix source string.

Trait Implementations§

Source§

impl Clone for NixExpr

Source§

fn clone(&self) -> NixExpr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NixExpr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for NixExpr

Source§

fn eq(&self, other: &NixExpr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for NixExpr

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.