1use crate::{ URTypeString, Error, Result };
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct URType(String);
5
6impl URType {
7 pub fn new(ur_type: impl Into<String>) -> Result<URType> {
9 let ur_type = ur_type.into();
10 if !ur_type.is_ur_type() {
11 return Err(Error::InvalidType);
12 }
13 Ok(URType(ur_type))
14 }
15
16 pub fn string(&self) -> &str {
18 &self.0
19 }
20}
21
22impl TryFrom<String> for URType {
23 type Error = Error;
24
25 fn try_from(value: String) -> Result<Self> {
26 URType::new(value)
27 }
28}
29
30impl TryFrom<&str> for URType {
31 type Error = Error;
32
33 fn try_from(value: &str) -> Result<Self> {
34 URType::new(value)
35 }
36}