devela/num/primitive/
namespace.rs
1#[doc = crate::TAG_NAMESPACE!()]
4#[repr(transparent)]
12pub struct Cast<T>(pub T);
13
14mod core_impls {
15 use crate::{Cast, ConstDefault, Ordering, _core::fmt};
16
17 impl<T: Clone> Clone for Cast<T> {
18 #[must_use]
19 fn clone(&self) -> Self {
20 Cast(self.0.clone())
21 }
22 }
23 impl<T: Copy> Copy for Cast<T> {}
24
25 impl<T: Default> Default for Cast<T> {
26 #[must_use]
27 fn default() -> Self {
28 Cast(T::default())
29 }
30 }
31
32 impl<T: ConstDefault> ConstDefault for Cast<T> {
33 const DEFAULT: Self = Cast(T::DEFAULT);
34 }
35
36 impl<T: PartialEq> PartialEq for Cast<T> {
37 #[must_use]
38 fn eq(&self, other: &Self) -> bool {
39 self.0.eq(&other.0)
40 }
41 }
42 impl<T: Eq> Eq for Cast<T> {}
43
44 impl<T: PartialOrd> PartialOrd for Cast<T> {
45 #[must_use]
46 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
47 self.0.partial_cmp(&other.0)
48 }
49 }
50 impl<T: Ord> Ord for Cast<T> {
51 #[must_use]
52 fn cmp(&self, other: &Self) -> Ordering {
53 self.0.cmp(&other.0)
54 }
55 }
56
57 impl<T: fmt::Debug> fmt::Debug for Cast<T> {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 fmt::Debug::fmt(&self.0, f)
60 }
61 }
62 impl<T: fmt::Display> fmt::Display for Cast<T> {
63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64 fmt::Display::fmt(&self.0, f)
65 }
66 }
67}