lewp_css/domain/at_rules/namespace/
namespace_prefix.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::Atom,
6    cssparser::ToCss,
7    std::fmt::{self, Display, Formatter},
8};
9
10#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
11pub struct NamespacePrefix(pub Atom);
12
13impl ToCss for NamespacePrefix {
14    // https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSNamespaceRule
15    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
16        self.0.to_css(dest)
17    }
18}
19
20impl Default for NamespacePrefix {
21    #[inline(always)]
22    fn default() -> Self {
23        NamespacePrefix(Atom::default())
24    }
25}
26
27impl Display for NamespacePrefix {
28    #[inline(always)]
29    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
30        self.0.fmt(f)
31    }
32}
33
34impl From<String> for NamespacePrefix {
35    #[inline(always)]
36    fn from(value: String) -> Self {
37        NamespacePrefix(Atom::from(value))
38    }
39}
40
41impl<'a> From<&'a str> for NamespacePrefix {
42    #[inline(always)]
43    fn from(value: &'a str) -> Self {
44        NamespacePrefix(Atom::from(value))
45    }
46}