-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.go
53 lines (41 loc) · 804 Bytes
/
basic.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
package types
import (
"fmt"
"github.com/verniyyy/extend-types-go/lib"
"golang.org/x/exp/constraints"
)
type basic[T constraints.Ordered] struct {
v T
}
func newBasic[T constraints.Ordered](v T) basic[T] {
return basic[T]{
v: v,
}
}
func (b basic[T]) Value() T {
return b.v
}
func (b basic[T]) String() string {
return fmt.Sprint(b.v)
}
func (b basic[T]) Ptr() *T {
return &b.v
}
func (b basic[T]) Equal(v T) bool {
return b.v == v
}
func (b basic[T]) DeepEqual(v T) bool {
return lib.DeepEqual(b.v, v)
}
// Print with label.
// if label="example" then output:
// example: ${b.v}
func (b basic[T]) Print(label string) {
fmt.Printf("%s: %v\n", label, b.v)
}
func (b basic[T]) CoreTypeName() string {
return lib.TypeName(b.v)
}
func (b basic[T]) Validate() error {
return nil
}