@@ -9,7 +9,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
9
9
if len (cases ) <= linearScanThreshold {
10
10
return func (v * T , text []byte ) error {
11
11
if len (text ) == 0 {
12
- return errEmpty
12
+ return & emptyTextError {}
13
13
}
14
14
s := string (text )
15
15
for i := 0 ; i < len (cases ); i ++ {
@@ -18,7 +18,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
18
18
return nil
19
19
}
20
20
}
21
- return errNoMatchingCase
21
+ return & noMatchingCaseError {}
22
22
}
23
23
}
24
24
@@ -29,11 +29,11 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
29
29
30
30
return func (v * T , text []byte ) error {
31
31
if len (text ) == 0 {
32
- return errEmpty
32
+ return & emptyTextError {}
33
33
}
34
34
c , ok := m [string (text )]
35
35
if ! ok {
36
- return errNoMatchingCase
36
+ return & noMatchingCaseError {}
37
37
}
38
38
* v = c
39
39
return nil
@@ -42,15 +42,10 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
42
42
43
43
const linearScanThreshold = 16
44
44
45
- var (
46
- errEmpty = & stringError {"empty text" }
47
- errNoMatchingCase = & stringError {"no matching case" }
48
- )
45
+ type emptyTextError struct {}
49
46
50
- type stringError struct {
51
- err string
52
- }
47
+ func (* emptyTextError ) Error () string { return "empty text" }
53
48
54
- func ( err * stringError ) Error () string {
55
- return err . err
56
- }
49
+ type noMatchingCaseError struct {}
50
+
51
+ func ( * noMatchingCaseError ) Error () string { return "no matching case" }
0 commit comments