authly_common/
property.rs

1//! Authly property utilities.
2use std::str::FromStr;
3
4use serde::Deserialize;
5
6use crate::FromStrVisitor;
7
8/// A qualified attribute name, in the context of a service.
9///
10/// Consists of a property and an attribute of that property.
11#[derive(Debug)]
12pub struct QualifiedAttributeName {
13    /// The namespace
14    pub namespace: String,
15
16    /// The property name.
17    pub property: String,
18
19    /// The attribute name.
20    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}