saml_rs/model/
attributes.rs1#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct AttributeValue(String);
4
5impl AttributeValue {
6 pub fn new(value: impl Into<String>) -> Self {
8 Self(value.into())
9 }
10
11 pub fn as_str(&self) -> &str {
13 &self.0
14 }
15}
16
17#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct Attribute {
20 name: String,
21 name_format: Option<String>,
22 values: Vec<AttributeValue>,
23}
24
25impl Attribute {
26 pub fn new(
28 name: impl Into<String>,
29 name_format: Option<String>,
30 values: Vec<AttributeValue>,
31 ) -> Self {
32 Self {
33 name: name.into(),
34 name_format,
35 values,
36 }
37 }
38
39 pub fn name(&self) -> &str {
41 &self.name
42 }
43
44 pub fn name_format(&self) -> Option<&str> {
46 self.name_format.as_deref()
47 }
48
49 pub fn values(&self) -> &[AttributeValue] {
51 &self.values
52 }
53}
54
55#[derive(Debug, Clone, Default, PartialEq, Eq)]
57pub struct Attributes(Vec<Attribute>);
58
59impl Attributes {
60 pub fn new(values: Vec<Attribute>) -> Self {
62 Self(values)
63 }
64
65 pub fn as_slice(&self) -> &[Attribute] {
67 &self.0
68 }
69
70 pub fn get(&self, name: &str) -> Option<&Attribute> {
72 self.0.iter().find(|attribute| attribute.name() == name)
73 }
74}
75
76impl IntoIterator for Attributes {
77 type Item = Attribute;
78 type IntoIter = std::vec::IntoIter<Attribute>;
79
80 fn into_iter(self) -> Self::IntoIter {
81 self.0.into_iter()
82 }
83}