Skip to main content

lewp_css/domain/at_rules/import/
import_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    crate::domain::{at_rules::media::MediaList, SpecifiedUrl},
6    cssparser::ToCss,
7    std::fmt,
8};
9
10/// The [`@import`][import] at-rule.
11///
12/// [import]: <https://drafts.csswg.org/css-cascade-3/#at-import>
13#[derive(Debug, Clone)]
14pub struct ImportAtRule {
15    /// The `<url>` this `@import` rule is loading.
16    pub url: SpecifiedUrl,
17
18    pub media_list: MediaList,
19}
20
21impl ToCss for ImportAtRule {
22    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
23        dest.write_str("@import ")?;
24        self.url.to_css(dest)?;
25
26        if self.media_list.is_not_empty() {
27            dest.write_char(' ')?;
28            self.media_list.to_css(dest)?;
29        }
30
31        dest.write_char(';')
32    }
33}