scientific_workflow/state/
field.rs1use serde::Serialize;
4
5#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
10pub struct StateFieldSchema {
11 #[serde(skip)]
12 index: usize,
13 name: Box<str>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 description: Option<Box<str>>,
16}
17
18impl StateFieldSchema {
19 pub(super) fn new(index: usize, name: &str, description: Option<&str>) -> Self {
20 Self {
21 index,
22 name: name.trim().into(),
23 description: description
24 .map(str::trim)
25 .filter(|description| !description.is_empty())
26 .map(Into::into),
27 }
28 }
29
30 pub fn position(&self) -> usize {
32 self.index
33 }
34
35 pub fn name(&self) -> &str {
37 &self.name
38 }
39
40 pub fn description(&self) -> Option<&str> {
42 self.description.as_deref()
43 }
44
45 pub(super) fn owned_name(&self) -> Box<str> {
46 self.name.clone()
47 }
48}