lewp_css/domain/at_rules/namespace/namespace_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::{NamespacePrefix, NamespaceUrl},
6 cssparser::ToCss,
7 std::fmt,
8};
9
10/// A `@namespace` rule.
11#[derive(Clone, Debug, PartialEq)]
12#[allow(missing_docs)]
13pub struct NamespaceAtRule {
14 /// The namespace prefix, and `None` if it's the default Namespace
15 pub prefix: Option<NamespacePrefix>,
16
17 /// The actual namespace url.
18 pub url: NamespaceUrl,
19}
20
21impl ToCss for NamespaceAtRule {
22 // https://drafts.csswg.org/cssom/#serialize-a-css-rule
23 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
24 dest.write_str("@namespace ")?;
25
26 if let Some(ref prefix) = self.prefix {
27 dest.write_str(&(prefix.0).0)?;
28 dest.write_str(" ")?;
29 }
30
31 dest.write_str("url(")?;
32 dest.write_str(&(self.url.0).0)?;
33 dest.write_str(");")
34 }
35}