hash_str/
ornaments.rs

1// === Ornaments ===
2// Bells and whistles.
3// Convenient impls which may obscure
4// the readability of the core implementations.
5
6use crate::hash_str::HashStr;
7
8impl core::ops::Deref for HashStr{
9	type Target=str;
10	#[inline]
11	fn deref(&self)->&Self::Target{
12		self.as_str()
13	}
14}
15
16impl core::fmt::Display for HashStr{
17	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18		f.write_str(self.as_str())
19	}
20}
21
22macro_rules! partial_eq_lhs_as_str{
23	($lhs:ty,$rhs:ty)=>{
24		impl PartialEq<$rhs> for $lhs {
25			fn eq(&self, other: &$rhs) -> bool {
26				self.as_str() == other
27			}
28		}
29		impl PartialEq<$lhs> for $rhs {
30			fn eq(&self, other: &$lhs) -> bool {
31				self == other.as_str()
32			}
33		}
34	};
35}
36macro_rules! partial_eq_lhs_as_str_rhs_deref{
37	($lhs:ty,$rhs:ty)=>{
38		impl PartialEq<$rhs> for $lhs {
39			fn eq(&self, &other: &$rhs) -> bool {
40				self.as_str() == other
41			}
42		}
43		impl PartialEq<$lhs> for $rhs {
44			fn eq(&self, other: &$lhs) -> bool {
45				*self == other.as_str()
46			}
47		}
48	};
49}
50macro_rules! partial_eq_lhs_as_str_rhs_as_ref{
51	($lhs:ty,$rhs:ty)=>{
52		impl PartialEq<$rhs> for $lhs {
53			fn eq(&self, other: &$rhs) -> bool {
54				self.as_str() == other.as_ref()
55			}
56		}
57		impl PartialEq<$lhs> for $rhs {
58			fn eq(&self, other: &$lhs) -> bool {
59				self.as_ref() == other.as_str()
60			}
61		}
62	};
63}
64partial_eq_lhs_as_str!(HashStr,str);
65partial_eq_lhs_as_str!(HashStr,String);
66partial_eq_lhs_as_str_rhs_deref!(HashStr,&str);
67partial_eq_lhs_as_str_rhs_deref!(HashStr,&String);
68partial_eq_lhs_as_str_rhs_as_ref!(HashStr,Box<str>);
69partial_eq_lhs_as_str_rhs_as_ref!(HashStr,&Box<str>);
70use std::borrow::Cow;
71partial_eq_lhs_as_str_rhs_as_ref!(HashStr,Cow<'_,str>);
72partial_eq_lhs_as_str_rhs_as_ref!(HashStr,&Cow<'_,str>);
73
74// TODO:
75// Path and OsStr requre CStr
76// use std::path::Path;
77// use std::ffi::OsStr;