protoflow_core/
parameter_descriptor.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::prelude::{Cow, MaybeLabeled, Named, String};
4
5/// A descriptor for a block parameter.
6#[derive(Clone, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct ParameterDescriptor {
9    /// The machine-readable name of this parameter.
10    pub name: String,
11
12    /// A human-readable label, if any, for this parameter.
13    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
14    pub label: Option<String>,
15
16    /// The data type, if known, of this parameter.
17    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
18    pub r#type: Option<String>,
19
20    /// A default value, if any, for this parameter.
21    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
22    pub default_value: Option<String>,
23}
24
25impl Named for ParameterDescriptor {
26    fn name(&self) -> Cow<str> {
27        Cow::Borrowed(&self.name)
28    }
29}
30
31impl MaybeLabeled for ParameterDescriptor {
32    fn label(&self) -> Option<Cow<str>> {
33        self.label.as_deref().map(Cow::Borrowed)
34    }
35}