Skip to main content

lewp_css/domain/at_rules/supports/
supports_at_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::SupportsCondition,
6    crate::domain::{CssRule, CssRules, HasCssRules},
7    cssparser::ToCss,
8    std::fmt,
9};
10
11/// An [`@supports`][supports] rule.
12///
13/// [supports]: <https://drafts.csswg.org/css-conditional-3/#at-supports>
14#[derive(Debug, Clone)]
15pub struct SupportsAtRule {
16    /// The parsed condition
17    pub condition: SupportsCondition,
18
19    /// Child rules
20    pub rules: CssRules,
21}
22
23impl HasCssRules for SupportsAtRule {
24    #[inline(always)]
25    fn css_rules(&self) -> &CssRules {
26        &self.rules
27    }
28
29    #[inline(always)]
30    fn css_rules_mut(&mut self) -> &mut CssRules {
31        &mut self.rules
32    }
33
34    #[inline(always)]
35    fn css_rules_slice(&self) -> &[CssRule] {
36        &self.rules.0[..]
37    }
38
39    #[inline(always)]
40    fn css_rules_vec(&self) -> &Vec<CssRule> {
41        &self.rules.0
42    }
43
44    #[inline(always)]
45    fn css_rules_vec_mut(&mut self) -> &mut Vec<CssRule> {
46        &mut self.rules.0
47    }
48}
49
50impl ToCss for SupportsAtRule {
51    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
52        dest.write_str("@supports ")?;
53        self.condition.to_css(dest)?;
54        dest.write_char('{')?;
55        self.rules.to_css(dest)?;
56        dest.write_char('}')
57    }
58}