-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt.go
187 lines (142 loc) · 3.56 KB
/
fmt.go
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
package gost
import (
"fmt"
"reflect"
)
// Format trait for an empty format, {}
type Display[T any] interface {
Display() String
}
func (self ISize) Display() String {
return self.ToString()
}
func (self I8) Display() String {
return self.ToString()
}
func (self I16) Display() String {
return self.ToString()
}
func (self I32) Display() String {
return self.ToString()
}
func (self I64) Display() String {
return self.ToString()
}
func (self I128) Display() String {
return self.ToString()
}
func (self USize) Display() String {
return self.ToString()
}
func (self U8) Display() String {
return self.ToString()
}
func (self U16) Display() String {
return self.ToString()
}
func (self U32) Display() String {
return self.ToString()
}
func (self U64) Display() String {
return self.ToString()
}
func (self U128) Display() String {
return self.ToString()
}
func (self F32) Display() String {
return self.ToString()
}
func (self F64) Display() String {
return self.ToString()
}
func (self Byte) Display() String {
return self.ToString()
}
func (self Char) Display() String {
return self.ToString()
}
func (self String) Display() String {
return self
}
func (self Bool) Display() String {
return self.ToString()
}
func (self Complex64) Display() String {
return self.ToString()
}
func (self Complex128) Display() String {
return self.ToString()
}
func castToDisplay[T any](value T) Option[Display[T]] {
reflectedValue := reflect.ValueOf(value)
if display, ok := reflectedValue.Interface().(Display[T]); ok {
return Some[Display[T]](display)
} else {
return None[Display[T]]()
}
}
// ? formatting.
// Debug should format the output in a programmer-facing, debugging context.
type Debug[T any] interface {
Debug() string
}
func (self ISize) Debug() String {
return String(fmt.Sprintf("ISize(%s)", self.ToString()))
}
func (self I8) Debug() String {
return String(fmt.Sprintf("I8(%s)", self.ToString()))
}
func (self I16) Debug() String {
return String(fmt.Sprintf("I16(%s)", self.ToString()))
}
func (self I32) Debug() String {
return String(fmt.Sprintf("I32(%s)", self.ToString()))
}
func (self I64) Debug() String {
return String(fmt.Sprintf("I64(%s)", self.ToString()))
}
func (self I128) Debug() String {
return String(fmt.Sprintf("I128(%s)", self.ToString()))
}
func (self USize) Debug() String {
return String(fmt.Sprintf("USize(%s)", self.ToString()))
}
func (self U8) Debug() String {
return String(fmt.Sprintf("U8(%s)", self.ToString()))
}
func (self U16) Debug() String {
return String(fmt.Sprintf("U16(%s)", self.ToString()))
}
func (self U32) Debug() String {
return String(fmt.Sprintf("U32(%s)", self.ToString()))
}
func (self U64) Debug() String {
return String(fmt.Sprintf("U64(%s)", self.ToString()))
}
func (self U128) Debug() String {
return String(fmt.Sprintf("U128(%s)", self.ToString()))
}
func (self F32) Debug() String {
return String(fmt.Sprintf("F32(%s)", self.ToString()))
}
func (self F64) Debug() String {
return String(fmt.Sprintf("F64(%s)", self.ToString()))
}
func (self Byte) Debug() String {
return String(fmt.Sprintf("Byte(%s)", self.ToString()))
}
func (self Char) Debug() String {
return String(fmt.Sprintf("Char(%s)", self.ToString()))
}
func (self String) Debug() String {
return String(fmt.Sprintf("String(%s)", self))
}
func (self Bool) Debug() String {
return String(fmt.Sprintf("Bool(%s)", self.ToString()))
}
func (self Complex64) Debug() String {
return String(fmt.Sprintf("Complex64(%s)", self.ToString()))
}
func (self Complex128) Debug() String {
return String(fmt.Sprintf("Complex128(%s)", self.ToString()))
}