nu_protocol/
example.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
use crate::Value;
#[cfg(feature = "plugin")]
use serde::{Deserialize, Serialize};

#[derive(Debug)]
pub struct Example<'a> {
    pub example: &'a str,
    pub description: &'a str,
    pub result: Option<Value>,
}

// PluginExample is somehow like struct `Example`, but it owned a String for `example`
// and `description` fields, because these information is fetched from plugin, a third party
// binary, nushell have no way to construct it directly.
#[cfg(feature = "plugin")]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PluginExample {
    pub example: String,
    pub description: String,
    pub result: Option<Value>,
}

#[cfg(feature = "plugin")]
impl From<Example<'_>> for PluginExample {
    fn from(value: Example) -> Self {
        PluginExample {
            example: value.example.into(),
            description: value.description.into(),
            result: value.result,
        }
    }
}