lewp_css/domain/properties/
importance.rs1use {
5 super::HasImportance,
6 crate::CustomParseError,
7 cssparser::{parse_important, ParseError, Parser, ToCss},
8 std::fmt,
9 Importance::*,
10};
11
12#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
16pub enum Importance {
17 Normal,
19
20 Important,
22}
23
24impl Default for Importance {
25 #[inline(always)]
26 fn default() -> Self {
27 Importance::Normal
28 }
29}
30
31impl ToCss for Importance {
32 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
33 match *self {
34 Normal => Ok(()),
35 Important => dest.write_str("!important"),
36 }
37 }
38}
39
40impl HasImportance for Importance {
41 #[inline(always)]
42 fn validateParsedImportance<'i>(
43 importance: Importance,
44 ) -> Result<Self, ParseError<'i, CustomParseError<'i>>> {
45 Ok(importance)
46 }
47
48 #[inline(always)]
50 fn isImportant(&self) -> bool {
51 match *self {
52 Normal => false,
53 Important => true,
54 }
55 }
56}
57
58impl Importance {
59 #[inline(always)]
60 pub fn from_bool(isImportant: bool) -> Self {
61 if isImportant {
62 Important
63 } else {
64 Normal
65 }
66 }
67
68 #[inline(always)]
69 pub(crate) fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Self {
70 Self::from_bool(input.r#try(parse_important).is_ok())
71 }
72}