-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstraints.go
50 lines (40 loc) · 1.34 KB
/
constraints.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
package attr
import "time"
// IntRestriction is a constraint that only accepts int values
type IntRestriction interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
// UintRestriction is a constraint that only accepts uint values
type UintRestriction interface {
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}
// FloatRestriction is a constraint that only accepts float values
type FloatRestriction interface {
~float32 | ~float64
}
// ComplexRestriction is a constraint that only accepts complex values
type ComplexRestriction interface {
~complex64 | ~complex128
}
// NumberRestriction is a constraint that only accepts number values,
// as a combination of other constraints
type NumberRestriction interface {
IntRestriction | UintRestriction | FloatRestriction | ComplexRestriction
}
// CharRestriction is a constraint that only accepts stringifiable tokens
type CharRestriction interface {
~string | ~byte | ~rune | ~[]byte | ~[]rune
}
// BoolRestriction is a constraint that only accepts booleans
type BoolRestriction interface {
~bool
}
// TimeRestriction is a constraint that only accepts time.Time values
type TimeRestriction interface {
time.Time
}
// TextRestriction is a constraint that only accepts text values,
// as a combination of other constraints
type TextRestriction interface {
CharRestriction | BoolRestriction | TimeRestriction
}