@@ -9,7 +9,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
99 if len (cases ) <= linearScanThreshold {
1010 return func (v * T , text []byte ) error {
1111 if len (text ) == 0 {
12- return errEmpty
12+ return & emptyTextError {}
1313 }
1414 s := string (text )
1515 for i := 0 ; i < len (cases ); i ++ {
@@ -18,7 +18,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
1818 return nil
1919 }
2020 }
21- return errNoMatchingCase
21+ return & noMatchingCaseError {}
2222 }
2323 }
2424
@@ -29,11 +29,11 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
2929
3030 return func (v * T , text []byte ) error {
3131 if len (text ) == 0 {
32- return errEmpty
32+ return & emptyTextError {}
3333 }
3434 c , ok := m [string (text )]
3535 if ! ok {
36- return errNoMatchingCase
36+ return & noMatchingCaseError {}
3737 }
3838 * v = c
3939 return nil
@@ -42,15 +42,10 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
4242
4343const linearScanThreshold = 16
4444
45- var (
46- errEmpty = & stringError {"empty text" }
47- errNoMatchingCase = & stringError {"no matching case" }
48- )
45+ type emptyTextError struct {}
4946
50- type stringError struct {
51- err string
52- }
47+ func (* emptyTextError ) Error () string { return "empty text" }
5348
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