html_types/semantic/
id.rs

1use crate::attributes::Value;
2
3pub struct Id(String);
4
5#[derive(Debug)]
6pub struct InvalidId();
7
8impl Id {
9    pub fn create<S>(id: S) -> Result<Id, InvalidId>
10    where
11        S: Into<String>,
12    {
13        let id = id.into();
14        let is_valid_value = Value::is_valid(&id);
15        match is_valid_value {
16            true => Ok(Id(id)),
17            false => Err(InvalidId()),
18        }
19    }
20}
21
22impl<'a> From<Id> for Value<'a> {
23    fn from(value: Id) -> Self {
24        let text = value.0;
25        //Note: Can only be constructed if it is a valid value
26        //ID constructor checks this. So this case is always successful
27        Value::owned(text).unwrap()
28    }
29}