scsys_core/id/impls/
impl_id.rs

1/*
2    appellation: impl_id <module>
3    authors: @FL03
4*/
5use crate::id::Id;
6
7impl<T> Id<&T> {
8    /// returns a new identifier with a cloned inner value
9    pub fn cloned(&self) -> Id<T>
10    where
11        T: Clone,
12    {
13        Id(self.0.clone())
14    }
15    /// returns a new identifier with the inner value copied
16    pub fn copied(&self) -> Id<T>
17    where
18        T: Copy,
19    {
20        Id(*self.0)
21    }
22}
23
24impl<T> Id<&mut T> {
25    /// returns a new identifier with a cloned inner value
26    pub fn cloned(&self) -> Id<T>
27    where
28        T: Clone,
29    {
30        Id(self.0.clone())
31    }
32    /// returns a new identifier with the inner value copied
33    pub fn copied(&self) -> Id<T>
34    where
35        T: Copy,
36    {
37        Id(*self.0)
38    }
39}
40
41impl<T> AsRef<T> for Id<T> {
42    fn as_ref(&self) -> &T {
43        self.get()
44    }
45}
46
47impl<T> AsMut<T> for Id<T> {
48    fn as_mut(&mut self) -> &mut T {
49        self.get_mut()
50    }
51}
52
53impl<T> core::borrow::Borrow<T> for Id<T> {
54    fn borrow(&self) -> &T {
55        self.get()
56    }
57}
58
59impl<T> core::borrow::BorrowMut<T> for Id<T> {
60    fn borrow_mut(&mut self) -> &mut T {
61        self.get_mut()
62    }
63}
64
65impl<T> core::ops::Deref for Id<T> {
66    type Target = T;
67
68    fn deref(&self) -> &Self::Target {
69        self.get()
70    }
71}
72
73impl<T> core::ops::DerefMut for Id<T> {
74    fn deref_mut(&mut self) -> &mut Self::Target {
75        self.get_mut()
76    }
77}
78
79impl<Q> PartialEq<Q> for Id<Q>
80where
81    Q: PartialEq,
82{
83    fn eq(&self, other: &Q) -> bool {
84        self.get() == other
85    }
86}
87
88impl<'a, Q> PartialEq<&'a Q> for Id<Q>
89where
90    Q: PartialEq,
91{
92    fn eq(&self, other: &&'a Q) -> bool {
93        self.get() == *other
94    }
95}
96
97impl<'a, Q> PartialEq<&'a mut Q> for Id<Q>
98where
99    Q: PartialEq,
100{
101    fn eq(&self, other: &&'a mut Q) -> bool {
102        self.get() == *other
103    }
104}
105
106impl<Q> PartialOrd<Q> for Id<Q>
107where
108    Q: PartialOrd,
109{
110    fn partial_cmp(&self, other: &Q) -> Option<core::cmp::Ordering> {
111        self.get().partial_cmp(other)
112    }
113}
114
115crate::fmt_wrapper! {
116    Id<T>(
117        Binary,
118        Debug,
119        Display,
120        LowerExp,
121        LowerHex,
122        Octal,
123        Pointer,
124        UpperExp,
125        UpperHex
126    )
127}