nate_common/
raw_marker.rs

1#![no_implicit_prelude]
2
3use std::prelude::v1::*;
4
5use crate::details::{alloc, std};
6use crate::XmlEscape;
7
8/// Types implementing this marker don't need to be escaped.
9pub trait RawMarker {}
10
11impl<T: RawMarker> RawMarker for &T {}
12impl<T: RawMarker> RawMarker for &mut T {}
13
14impl<T> RawMarker for XmlEscape<T> {}
15
16impl RawMarker for bool {}
17impl RawMarker for f32 {}
18impl RawMarker for f64 {}
19impl RawMarker for i128 {}
20impl RawMarker for i16 {}
21impl RawMarker for i32 {}
22impl RawMarker for i64 {}
23impl RawMarker for i8 {}
24impl RawMarker for isize {}
25impl RawMarker for u128 {}
26impl RawMarker for u16 {}
27impl RawMarker for u32 {}
28impl RawMarker for u64 {}
29impl RawMarker for u8 {}
30impl RawMarker for usize {}
31
32impl RawMarker for std::num::NonZeroI8 {}
33impl RawMarker for std::num::NonZeroI16 {}
34impl RawMarker for std::num::NonZeroI32 {}
35impl RawMarker for std::num::NonZeroI64 {}
36impl RawMarker for std::num::NonZeroI128 {}
37impl RawMarker for std::num::NonZeroIsize {}
38impl RawMarker for std::num::NonZeroU8 {}
39impl RawMarker for std::num::NonZeroU16 {}
40impl RawMarker for std::num::NonZeroU32 {}
41impl RawMarker for std::num::NonZeroU64 {}
42impl RawMarker for std::num::NonZeroU128 {}
43impl RawMarker for std::num::NonZeroUsize {}
44
45impl<T: RawMarker> RawMarker for std::cell::Ref<'_, T> {}
46impl<T: RawMarker> RawMarker for std::cell::RefMut<'_, T> {}
47impl<T: RawMarker> RawMarker for std::num::Wrapping<T> {}
48impl<T: RawMarker> RawMarker for std::pin::Pin<T> {}
49
50#[cfg(feature = "alloc")]
51const _: () = {
52    #[cfg_attr(feature = "docsrs", doc(cfg(any(feature = "std", feature = "alloc"))))]
53    impl<T: RawMarker + alloc::borrow::ToOwned> RawMarker for alloc::borrow::Cow<'_, T> {}
54    #[cfg_attr(feature = "docsrs", doc(cfg(any(feature = "std", feature = "alloc"))))]
55    impl<T: RawMarker> RawMarker for alloc::boxed::Box<T> {}
56    #[cfg_attr(feature = "docsrs", doc(cfg(any(feature = "std", feature = "alloc"))))]
57    impl<T: RawMarker> RawMarker for alloc::rc::Rc<T> {}
58    #[cfg_attr(feature = "docsrs", doc(cfg(any(feature = "std", feature = "alloc"))))]
59    impl<T: RawMarker> RawMarker for alloc::sync::Arc<T> {}
60};
61
62#[cfg(feature = "std")]
63const _: () = {
64    #[cfg_attr(feature = "docsrs", doc(cfg(feature = "std")))]
65    impl<T: RawMarker> RawMarker for std::sync::MutexGuard<'_, T> {}
66    #[cfg_attr(feature = "docsrs", doc(cfg(feature = "std")))]
67    impl<T: RawMarker> RawMarker for std::sync::RwLockReadGuard<'_, T> {}
68    #[cfg_attr(feature = "docsrs", doc(cfg(feature = "std")))]
69    impl<T: RawMarker> RawMarker for std::sync::RwLockWriteGuard<'_, T> {}
70};
71
72#[doc(hidden)]
73#[derive(Debug, Clone, Copy, Default)]
74pub struct RawTag;
75
76#[doc(hidden)]
77#[derive(Debug, Clone, Copy, Default)]
78pub struct EscapeTag;
79
80#[doc(hidden)]
81impl EscapeTag {
82    #[inline]
83    pub fn wrap<T>(&self, value: T) -> XmlEscape<T> {
84        XmlEscape(value)
85    }
86}