use crate::{utils::URTypeString, error::URError};
use anyhow::{Error, Result, bail};
#[derive(Debug, Clone, PartialEq)]
pub struct URType(String);
impl URType {
pub fn new(ur_type: impl Into<String>) -> Result<URType> {
let ur_type = ur_type.into();
if !ur_type.is_ur_type() {
bail!(URError::InvalidType);
}
Ok(URType(ur_type))
}
pub fn string(&self) -> &str {
&self.0
}
}
impl TryFrom<String> for URType {
type Error = Error;
fn try_from(value: String) -> Result<Self> {
URType::new(value)
}
}
impl TryFrom<&str> for URType {
type Error = Error;
fn try_from(value: &str) -> Result<Self> {
URType::new(value)
}
}