contack/
org.rs

1#[cfg(feature = "read_write")]
2use crate::read_write::component::Component;
3
4/// Represents an organisation.
5#[derive(Debug, Clone, PartialEq, PartialOrd)]
6pub struct Org {
7    /// The organisation, ie "ABC, Inc."
8    pub org: String,
9    /// The unit, ie "North American Division"
10    pub unit: String,
11    /// The offiuce, ie "Marketing"
12    pub office: String,
13}
14
15impl Org {
16    /// Creates a new [`Org`]
17    #[must_use]
18    pub const fn new(org: String, unit: String, office: String) -> Self {
19        Self { org, unit, office }
20    }
21}
22
23#[cfg(feature = "read_write")]
24impl From<Org> for Component {
25    fn from(org: Org) -> Self {
26        Self {
27            name: "ORG".to_string(),
28            values: vec![vec![org.org], vec![org.unit], vec![org.office]],
29            ..Self::default()
30        }
31    }
32}
33
34#[cfg(feature = "read_write")]
35impl From<Component> for Org {
36    fn from(mut comp: Component) -> Self {
37        Self {
38            org: comp
39                .values
40                .get_mut(0)
41                .and_then(Vec::pop)
42                .unwrap_or_default(),
43            unit: comp
44                .values
45                .get_mut(1)
46                .and_then(Vec::pop)
47                .unwrap_or_default(),
48            office: comp
49                .values
50                .get_mut(2)
51                .and_then(Vec::pop)
52                .unwrap_or_default(),
53        }
54    }
55}