lewp_css/domain/
style_rule.rs

1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use {
5    super::{
6        properties::{Importance, PropertyDeclaration, PropertyDeclarations},
7        selectors::DeduplicatedSelectors,
8        HasPropertyDeclarations,
9    },
10    cssparser::ToCss,
11    std::fmt,
12};
13
14/// A style rule, with selectors and declarations.
15#[derive(Debug, Clone)]
16pub struct StyleRule {
17    /// The list of selectors in this rule.
18    pub selectors: DeduplicatedSelectors,
19
20    /// The declaration block with the properties it contains.
21    pub property_declarations: PropertyDeclarations<Importance>,
22}
23
24impl ToCss for StyleRule {
25    /// <https://drafts.csswg.org/cssom/#serialize-a-css-rule>
26    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
27        self.selectors.to_css(dest)?;
28
29        dest.write_char('{')?;
30
31        self.property_declarations.to_css(dest)?;
32
33        dest.write_char('}')
34    }
35}
36
37impl HasPropertyDeclarations<Importance> for StyleRule {
38    #[inline(always)]
39    fn property_declarations(&self) -> &PropertyDeclarations<Importance> {
40        &self.property_declarations
41    }
42
43    #[inline(always)]
44    fn property_declarations_mut(
45        &mut self,
46    ) -> &mut PropertyDeclarations<Importance> {
47        &mut self.property_declarations
48    }
49
50    #[inline(always)]
51    fn property_declarations_slice(
52        &self,
53    ) -> &[PropertyDeclaration<Importance>] {
54        &self.property_declarations.0[..]
55    }
56
57    #[inline(always)]
58    fn property_declarations_vec(
59        &self,
60    ) -> &Vec<PropertyDeclaration<Importance>> {
61        &self.property_declarations.0
62    }
63
64    #[inline(always)]
65    fn property_declarations_vec_mut(
66        &mut self,
67    ) -> &mut Vec<PropertyDeclaration<Importance>> {
68        &mut self.property_declarations.0
69    }
70}