lewp_css/domain/properties/
css_wide_keyword.rs1use {
5 cssparser::{Parser, ToCss},
6 std::fmt,
7};
8
9#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
11pub enum CssWideKeyword {
12 initial,
14
15 inherit,
17
18 unset,
20}
21
22impl ToCss for CssWideKeyword {
23 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
24 use self::CssWideKeyword::*;
25
26 let value = match *self {
27 initial => "initial",
28 inherit => "inherit",
29 unset => "unset",
30 };
31
32 dest.write_str(value)
33 }
34}
35
36impl CssWideKeyword {
37 #[inline(always)]
38 pub fn to_str(&self) -> &'static str {
39 use self::CssWideKeyword::*;
40
41 match *self {
42 initial => "initial",
43 inherit => "inherit",
44 unset => "unset",
45 }
46 }
47
48 #[inline(always)]
49 fn from_ident<'i>(ident: &str) -> Option<Self> {
50 use self::CssWideKeyword::*;
51
52 match_ignore_ascii_case! {
53 ident,
54
55 "initial" => Some(initial),
56
57 "inherit" => Some(inherit),
58
59 "unset" => Some(unset),
60
61 _ => None
62 }
63 }
64
65 #[inline(always)]
66 pub(crate) fn parse(input: &mut Parser) -> Result<Self, ()> {
67 let ident = input.expect_ident().map_err(|_| ())?.clone();
68 input.expect_exhausted().map_err(|_| ())?;
69 Self::from_ident(&ident).ok_or(())
70 }
71}