Skip to main content

nu_command/conversions/into/
value.rs

1use nu_engine::command_prelude::*;
2
3#[derive(Clone)]
4pub struct IntoValue;
5
6impl Command for IntoValue {
7    fn name(&self) -> &str {
8        "into value"
9    }
10
11    fn signature(&self) -> Signature {
12        Signature::build(self.name())
13            .description(self.description())
14            .extra_description(self.extra_description())
15            .input_output_type(Type::Any, Type::Any)
16            .category(Category::Conversions)
17    }
18
19    fn description(&self) -> &str {
20        "Convert custom values into base values."
21    }
22
23    fn extra_description(&self) -> &str {
24        "Custom values from plugins have a base value representation. \
25        This extracts that base value representation. \
26        For streams use `collect`."
27    }
28
29    fn search_terms(&self) -> Vec<&str> {
30        vec!["custom", "base", "convert", "conversion"]
31    }
32
33    fn examples(&self) -> Vec<Example<'_>> {
34        vec![]
35    }
36
37    fn run(
38        &self,
39        _engine_state: &EngineState,
40        _stack: &mut Stack,
41        _call: &Call,
42        input: PipelineData,
43    ) -> Result<PipelineData, ShellError> {
44        if let PipelineData::Value(v @ Value::Custom { .. }, metadata) = input {
45            let span = v.span();
46            let val = v.into_custom_value()?;
47            return Ok(PipelineData::value(val.to_base_value(span)?, metadata));
48        }
49
50        Ok(input)
51    }
52}