about summary refs log tree commit diff
path: root/tvix/eval/src/value/list.rs
blob: f9d85229410a4d4241a22865e29da24295bffec7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/// This module implements Nix lists.
use std::fmt::Display;

use super::Value;

#[derive(Clone, Debug, PartialEq)]
pub struct NixList(pub Vec<Value>);

impl Display for NixList {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("[ ")?;

        for v in &self.0 {
            v.fmt(f)?;
            f.write_str(" ")?;
        }

        f.write_str("]")
    }
}

impl NixList {
    pub fn concat(&self, other: &Self) -> Self {
        let mut lhs = self.clone();
        let mut rhs = other.clone();
        lhs.0.append(&mut rhs.0);
        lhs
    }
}