Skip to main content

things3_cloud/
arg_types.rs

1use std::fmt;
2use std::str::FromStr;
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5pub struct IdentifierToken(String);
6
7impl IdentifierToken {
8    pub fn as_str(&self) -> &str {
9        &self.0
10    }
11
12    pub fn into_inner(self) -> String {
13        self.0
14    }
15}
16
17impl FromStr for IdentifierToken {
18    type Err = String;
19
20    fn from_str(value: &str) -> Result<Self, Self::Err> {
21        let value = value.trim();
22        if value.is_empty() {
23            return Err("identifier cannot be empty".to_string());
24        }
25        Ok(Self(value.to_string()))
26    }
27}
28
29impl From<String> for IdentifierToken {
30    fn from(value: String) -> Self {
31        Self(value)
32    }
33}
34
35impl From<&str> for IdentifierToken {
36    fn from(value: &str) -> Self {
37        Self(value.to_string())
38    }
39}
40
41impl fmt::Display for IdentifierToken {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        write!(f, "{}", self.0)
44    }
45}