dawproject_rs/api/timeline_mods/
notes.rs

1#![allow(unused)]
2use {
3    super::super::{add_one_get, fake_rng},
4    fake::{Dummy, Fake, Faker},
5    serde::{Deserialize, Serialize},
6};
7
8use super::{note::Note, time_unit::TimeUnit};
9
10#[derive(Debug, Deserialize, Serialize, Clone, Dummy)]
11pub struct Notes {
12    // Extends timeline
13    #[serde(rename = "@id")]
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub id: Option<String>,
16    #[serde(rename = "@name")]
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub name: Option<String>, // attribute
19    #[serde(rename = "@color")]
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub color: Option<String>, // att
22    #[serde(rename = "@comment")]
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub comment: Option<String>, // att
25    #[serde(rename = "@track")]
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub track: Option<String>,
28    #[serde(rename = "@timeUnit")]
29    #[serde(skip_serializing_if = "Option::is_none", default)]
30    pub time_unit: Option<TimeUnit>,
31
32    #[serde(rename = "$value", default)]
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub notes_sequence: Option<Vec<Note>>,
35}
36
37impl Notes {
38    pub fn new_test() -> Self {
39        Self {
40            id: Some(format!("id{}", add_one_get())),
41            name: None,
42            color: None,
43            comment: None,
44            track: None,
45            time_unit: None,
46            notes_sequence: Some(vec![]),
47        }
48    }
49
50    pub fn new_fake() -> Self {
51        let o: Self = Faker.fake_with_rng(&mut fake_rng());
52        o
53    }
54}
55
56#[cfg(test)]
57mod tests {
58    use std::error::Error;
59
60    use {super::Notes, quick_xml::se::to_string};
61
62    #[test]
63    pub fn se_test() -> Result<(), Box<dyn Error>> {
64        let mut o = Notes::new_fake();
65
66        match to_string(&o) {
67            Ok(o) => println!("{}", o),
68            Err(err) => return Err(err.into()),
69        }
70
71        Ok(())
72    }
73}