xsd_parser/models/schema/
namespace_prefix.rs1use std::borrow::Cow;
2use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
3
4use crate::models::format_utf8_slice;
5
6#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
8pub struct NamespacePrefix(pub Cow<'static, [u8]>);
9
10impl NamespacePrefix {
11 pub const XS: Self = Self(Cow::Borrowed(b"xs"));
13
14 pub const XSI: Self = Self(Cow::Borrowed(b"xsi"));
16
17 pub const XML: Self = Self(Cow::Borrowed(b"xml"));
19}
20
21impl NamespacePrefix {
22 #[must_use]
24 pub fn new<X>(value: X) -> Self
25 where
26 X: Into<Cow<'static, [u8]>>,
27 {
28 Self(value.into())
29 }
30}
31
32impl<X> From<X> for NamespacePrefix
33where
34 X: Into<Cow<'static, [u8]>>,
35{
36 fn from(value: X) -> Self {
37 Self(value.into())
38 }
39}
40
41impl<'x> From<&'x Self> for NamespacePrefix {
42 fn from(value: &'x Self) -> Self {
43 value.clone()
44 }
45}
46
47impl Debug for NamespacePrefix {
48 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
49 write!(f, "NamespacePrefix(b\"")?;
50
51 format_utf8_slice(&self.0, f)?;
52
53 write!(f, "\")")?;
54
55 Ok(())
56 }
57}
58
59impl Display for NamespacePrefix {
60 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
61 format_utf8_slice(&self.0, f)
62 }
63}