authly_common/
property.rs1use std::str::FromStr;
3
4use serde::Deserialize;
5
6use crate::FromStrVisitor;
7
8#[derive(Debug)]
12pub struct QualifiedAttributeName {
13 pub namespace: String,
15
16 pub property: String,
18
19 pub attribute: String,
21}
22
23impl FromStr for QualifiedAttributeName {
24 type Err = &'static str;
25
26 fn from_str(s: &str) -> Result<Self, Self::Err> {
27 let mut segments = s.split(":");
28 let namespace = segments.next();
29 let property = segments.next();
30 let attribute = segments.next();
31
32 match (namespace, property, attribute) {
33 (Some(namespace), Some(property), Some(attribute)) => Ok(Self {
34 namespace: namespace.to_string(),
35 property: property.to_string(),
36 attribute: attribute.to_string(),
37 }),
38 _ => Err("expected qualified namespace/property/attribute triple"),
39 }
40 }
41}
42
43impl<'de> Deserialize<'de> for QualifiedAttributeName {
44 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
45 where
46 D: serde::Deserializer<'de>,
47 {
48 deserializer.deserialize_str(FromStrVisitor::new("attribute name"))
49 }
50}