Skip to main content

nu_protocol/config/
hinter.rs

1use super::prelude::*;
2use crate as nu_protocol;
3use crate::engine::Closure;
4
5#[derive(Clone, Debug, Default, IntoValue, Serialize, Deserialize)]
6pub struct HinterConfig {
7    pub closure: Option<Closure>,
8}
9
10impl UpdateFromValue for HinterConfig {
11    fn update<'a>(
12        &mut self,
13        value: &'a Value,
14        path: &mut ConfigPath<'a>,
15        errors: &mut ConfigErrors,
16    ) {
17        let Value::Record { val: record, .. } = value else {
18            errors.type_mismatch(path, Type::record(), value);
19            return;
20        };
21
22        for (col, val) in record.iter() {
23            let path = &mut path.push(col);
24            match col.as_str() {
25                "closure" => match val {
26                    Value::Nothing { .. } => self.closure = None,
27                    Value::Closure { val, .. } => self.closure = Some(val.as_ref().clone()),
28                    _ => errors.type_mismatch(path, Type::custom("closure or nothing"), val),
29                },
30                _ => errors.unknown_option(path, val),
31            }
32        }
33    }
34}