nu_protocol/pipeline/
metadata.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5/// Metadata that is valid for the whole [`PipelineData`](crate::PipelineData)
6#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
7pub struct PipelineMetadata {
8    pub data_source: DataSource,
9    pub content_type: Option<String>,
10}
11
12impl PipelineMetadata {
13    pub fn with_data_source(self, data_source: DataSource) -> Self {
14        Self {
15            data_source,
16            ..self
17        }
18    }
19
20    pub fn with_content_type(self, content_type: Option<String>) -> Self {
21        Self {
22            content_type,
23            ..self
24        }
25    }
26}
27
28/// Describes where the particular [`PipelineMetadata`] originates.
29///
30/// This can either be a particular family of commands (useful so downstream commands can adjust
31/// the presentation e.g. `Ls`) or the opened file to protect against overwrite-attempts properly.
32#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
33pub enum DataSource {
34    Ls,
35    HtmlThemes,
36    FilePath(PathBuf),
37    #[default]
38    None,
39}