dawproject_rs/api/
application.rs

1#![allow(unused)]
2
3use super::fake_rng;
4
5use {
6    fake::{Dummy, Fake, Faker},
7    serde::{Deserialize, Serialize},
8};
9#[derive(Debug, Deserialize, Serialize, Clone, Dummy)]
10pub struct Application {
11    #[serde(rename = "@name")]
12    pub name: String,
13    #[serde(rename = "@version")]
14    pub version: String,
15}
16
17impl Application {
18    pub fn new_empty() -> Self {
19        Application {
20            name: "".to_string(),
21            version: "".to_string(),
22        }
23    }
24
25    pub fn new_name_ver(name: String, version: f64) -> Self {
26        Application {
27            name,
28            version: version.to_string(),
29        }
30    }
31
32    pub fn new_fake() -> Self {
33        let o: Self = Faker.fake_with_rng(&mut fake_rng());
34        o
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use {super::Application, quick_xml::se::to_string, std::error::Error};
41
42    #[test]
43    pub fn se_test() -> Result<(), Box<dyn Error>> {
44        let mut o = Application::new_name_ver("test".to_string(), 1.0);
45
46        match to_string(&o) {
47            Ok(o) => println!("{}", o),
48            Err(err) => return Err(err.into()),
49        }
50
51        Ok(())
52    }
53}