nu_protocol/config/
filesize.rs

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
30
31
32
33
34
35
36
37
38
39
40
use super::prelude::*;
use crate as nu_protocol;

#[derive(Clone, Debug, IntoValue, PartialEq, Eq, Serialize, Deserialize)]
pub struct FilesizeConfig {
    pub metric: bool,
    pub format: String,
}

impl Default for FilesizeConfig {
    fn default() -> Self {
        Self {
            metric: false,
            format: "auto".into(),
        }
    }
}

impl UpdateFromValue for FilesizeConfig {
    fn update<'a>(
        &mut self,
        value: &'a Value,
        path: &mut ConfigPath<'a>,
        errors: &mut ConfigErrors,
    ) {
        let Value::Record { val: record, .. } = value else {
            errors.type_mismatch(path, Type::record(), value);
            return;
        };

        for (col, val) in record.iter() {
            let path = &mut path.push(col);
            match col.as_str() {
                "metric" => self.metric.update(val, path, errors),
                "format" => self.format.update(val, path, errors),
                _ => errors.unknown_option(path, val),
            }
        }
    }
}