nu_protocol/plugin/
metadata.rs

1use serde::{Deserialize, Serialize};
2
3/// Metadata about the installed plugin. This is cached in the registry file along with the
4/// signatures. None of the metadata fields are required, and more may be added in the future.
5#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
6#[non_exhaustive]
7pub struct PluginMetadata {
8    /// The version of the plugin itself, as self-reported.
9    pub version: Option<String>,
10}
11
12impl PluginMetadata {
13    /// Create empty metadata.
14    pub const fn new() -> PluginMetadata {
15        PluginMetadata { version: None }
16    }
17
18    /// Set the version of the plugin on the metadata. A suggested way to construct this is:
19    ///
20    /// ```no_run
21    /// # use nu_protocol::PluginMetadata;
22    /// # fn example() -> PluginMetadata {
23    /// PluginMetadata::new().with_version(env!("CARGO_PKG_VERSION"))
24    /// # }
25    /// ```
26    ///
27    /// which will use the version of your plugin's crate from its `Cargo.toml` file.
28    pub fn with_version(mut self, version: impl Into<String>) -> Self {
29        self.version = Some(version.into());
30        self
31    }
32}
33
34impl Default for PluginMetadata {
35    fn default() -> Self {
36        Self::new()
37    }
38}