1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
use std::{
	borrow::{Borrow, BorrowMut},
	fmt::{Debug, Display},
	ops::{Deref, DerefMut},
};

use serde::{Deserialize, Serialize};

use crate::errorx::NotError;

#[rustc_unsafe_specialization_marker]
pub trait Is<T> {}

impl<T> Is<T> for T {}

pub trait Irrelative {
	type Type;
}

impl<T> Irrelative for T
where
	T: ?Sized,
{
	type Type = !;
}

pub struct Equality<X, Y>(<X as Irrelative>::Type, <Y as Irrelative>::Type);
#[rustc_unsafe_specialization_marker]
pub auto trait NotEqual {}
impl<X> !NotEqual for Equality<X, X> {}

pub struct TypeMark<T>(<T as Irrelative>::Type)
where
	T: ?Sized;

#[rustc_specialization_trait]
trait SpecializedDebug = Debug;

trait DebugOrDefaultTrait {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;
}

impl<T> DebugOrDefaultTrait for T
where
	T: ?Sized,
{
	default fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		Ok(())
	}
}

impl<T> DebugOrDefaultTrait for T
where
	T: SpecializedDebug + ?Sized,
{
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		Debug::fmt(&self, f)
	}
}

#[rustc_specialization_trait]
trait SpecializedDisplay = Display;

trait DisplayOrDefaultTrait {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;
}

impl<T> DisplayOrDefaultTrait for T
where
	T: ?Sized,
{
	default fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		Ok(())
	}
}

impl<T> DisplayOrDefaultTrait for T
where
	T: SpecializedDisplay + ?Sized,
{
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		Display::fmt(&self, f)
	}
}

#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
#[repr(transparent)]
pub struct ImplDefault<T>(pub T)
where
	T: ?Sized;

impl<T> Debug for ImplDefault<T>
where
	T: ?Sized,
{
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		DebugOrDefaultTrait::fmt(&self.0, f)
	}
}

impl<T> Display for ImplDefault<T>
where
	T: ?Sized,
{
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		DisplayOrDefaultTrait::fmt(&self.0, f)
	}
}

pub auto trait NotImplDefault {}
impl<T> !NotImplDefault for TypeMark<ImplDefault<T>> {}

impl<T> From<T> for ImplDefault<T>
where
	TypeMark<T>: NotImplDefault,
{
	fn from(value: T) -> Self {
		Self(value)
	}
}

#[allow(clippy::from_over_into)]
impl<T> Into<T> for ImplDefault<T>
where
	TypeMark<T>: NotImplDefault,
	T: NotError,
{
	fn into(self) -> T {
		todo!()
	}
}

impl<T> Deref for ImplDefault<T>
where
	T: ?Sized,
{
	type Target = T;
	fn deref(&self) -> &Self::Target {
		&self.0
	}
}

impl<T> DerefMut for ImplDefault<T>
where
	T: ?Sized,
{
	fn deref_mut(&mut self) -> &mut Self::Target {
		&mut self.0
	}
}

impl<T> AsRef<T> for ImplDefault<T>
where
	T: ?Sized,
{
	fn as_ref(&self) -> &T {
		self
	}
}

impl<T> AsMut<T> for ImplDefault<T>
where
	T: ?Sized,
{
	fn as_mut(&mut self) -> &mut T {
		self
	}
}

impl<T> Borrow<T> for ImplDefault<T>
where
	T: ?Sized,
{
	fn borrow(&self) -> &T {
		self
	}
}

impl<T> BorrowMut<T> for ImplDefault<T>
where
	T: ?Sized,
{
	fn borrow_mut(&mut self) -> &mut T {
		self
	}
}