Skip to main content

sciforge_parser/html/
value.rs

1#[derive(Clone, Copy, Debug, PartialEq)]
2pub enum HtmlValue<'a> {
3    Document,
4    Element,
5    Text(&'a str),
6    Comment,
7    Doctype,
8}
9
10impl<'a> HtmlValue<'a> {
11    pub const fn is_document(&self) -> bool {
12        matches!(self, HtmlValue::Document)
13    }
14
15    pub const fn is_element(&self) -> bool {
16        matches!(self, HtmlValue::Element)
17    }
18
19    pub const fn is_comment(&self) -> bool {
20        matches!(self, HtmlValue::Comment)
21    }
22
23    pub const fn is_doctype(&self) -> bool {
24        matches!(self, HtmlValue::Doctype)
25    }
26
27    pub const fn as_text(&self) -> Option<&str> {
28        match self {
29            HtmlValue::Text(v) => Some(v),
30            _ => None,
31        }
32    }
33}