Skip to content

Commit e20904d

Browse files
committed
cm: use ResultOK and ResultErr
1 parent 23a4cae commit e20904d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

cm/result.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type result[Shape, OK, Err any] struct {
4444
func OK[R AnyResult[Shape, OK, Err], Shape, OK, Err any](ok OK) R {
4545
var r Result[Shape, OK, Err]
4646
r.validate()
47-
r.isErr = 0
47+
r.isErr = ResultOK
4848
*((*OK)(unsafe.Pointer(&r.data))) = ok
4949
return R(r)
5050
}
@@ -54,42 +54,42 @@ func OK[R AnyResult[Shape, OK, Err], Shape, OK, Err any](ok OK) R {
5454
func Err[R AnyResult[Shape, OK, Err], Shape, OK, Err any](err Err) R {
5555
var r Result[Shape, OK, Err]
5656
r.validate()
57-
r.isErr = 1
57+
r.isErr = ResultErr
5858
*((*Err)(unsafe.Pointer(&r.data))) = err
5959
return R(r)
6060
}
6161

6262
// SetOK sets r to an OK result.
6363
func (r *result[Shape, OK, Err]) SetOK(ok OK) {
6464
r.validate()
65-
r.isErr = 0
65+
r.isErr = ResultOK
6666
*((*OK)(unsafe.Pointer(&r.data))) = ok
6767
}
6868

6969
// SetErr sets r to an error result.
7070
func (r *result[Shape, OK, Err]) SetErr(err Err) {
7171
r.validate()
72-
r.isErr = 1
72+
r.isErr = ResultErr
7373
*((*Err)(unsafe.Pointer(&r.data))) = err
7474
}
7575

7676
// IsOK returns true if r represents the OK case.
7777
func (r *result[Shape, OK, Err]) IsOK() bool {
7878
r.validate()
79-
return r.isErr == 0
79+
return r.isErr == ResultOK
8080
}
8181

8282
// IsErr returns true if r represents the error case.
8383
func (r *result[Shape, OK, Err]) IsErr() bool {
8484
r.validate()
85-
return r.isErr == 1
85+
return r.isErr == ResultErr
8686
}
8787

8888
// OK returns a non-nil *OK pointer if r represents the OK case.
8989
// If r represents an error, then it returns nil.
9090
func (r *result[Shape, OK, Err]) OK() *OK {
9191
r.validate()
92-
if r.isErr == 1 {
92+
if r.isErr == ResultErr {
9393
return nil
9494
}
9595
return (*OK)(unsafe.Pointer(&r.data))
@@ -99,7 +99,7 @@ func (r *result[Shape, OK, Err]) OK() *OK {
9999
// If r represents the OK case, then it returns nil.
100100
func (r *result[Shape, OK, Err]) Err() *Err {
101101
r.validate()
102-
if r.isErr == 0 {
102+
if r.isErr == ResultOK {
103103
return nil
104104
}
105105
return (*Err)(unsafe.Pointer(&r.data))
@@ -109,7 +109,7 @@ func (r *result[Shape, OK, Err]) Err() *Err {
109109
// or (zero value of OK, Err, true) if r represents the error case.
110110
// This does not have a pointer receiver, so it can be chained.
111111
func (r result[Shape, OK, Err]) Result() (ok OK, err Err, isErr bool) {
112-
if r.isErr == 1 {
112+
if r.isErr == ResultErr {
113113
return ok, *(*Err)(unsafe.Pointer(&r.data)), true
114114
}
115115
return *(*OK)(unsafe.Pointer(&r.data)), err, false

0 commit comments

Comments
 (0)