lewp_css/domain/properties/
property_declaration.rs1use {
5 super::{HasImportance, UnparsedPropertyValue},
6 crate::domain::{Atom, HasVendorPrefix, VendorPrefix},
7 cssparser::ToCss,
8 std::fmt,
9};
10
11#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
12pub struct PropertyDeclaration<I: HasImportance> {
13 pub vendor_prefix: Option<VendorPrefix>,
14 pub name: Atom,
15 pub value: UnparsedPropertyValue,
16 pub importance: I,
17}
18
19impl<I: HasImportance> ToCss for PropertyDeclaration<I> {
20 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
21 self.to_css_without_trailing_semicolon(dest)?;
22 dest.write_char(';')
23 }
24}
25
26impl<I: HasImportance> HasVendorPrefix for PropertyDeclaration<I> {
27 #[inline(always)]
28 fn isNotVendorPrefixed(&self) -> bool {
29 self.vendor_prefix.is_none()
30 }
31}
32
33impl<I: HasImportance> PropertyDeclaration<I> {
34 #[inline(always)]
36 pub fn hasACustomPropertyName(&self) -> bool {
37 self.name.starts_with("--")
38 }
39
40 #[inline(always)]
41 pub fn hasAsciiNameIgnoringCase(&self, name: &str) -> bool {
42 self.name.eq_ignore_ascii_case(name)
43 }
44
45 #[inline(always)]
46 pub(crate) fn to_css_without_trailing_semicolon<W: fmt::Write>(
47 &self,
48 dest: &mut W,
49 ) -> fmt::Result {
50 if let Some(ref vendorPrefix) = self.vendor_prefix {
51 vendorPrefix.to_css(dest)?;
52 }
53 self.name.to_css(dest)?;
54 dest.write_char(':')?;
55 self.value.to_css(dest)?;
56 self.importance.to_css(dest)
57 }
58}