@@ -33,7 +33,7 @@ type AnyResult[Shape, OK, Err any] interface {
3333// result represents the internal representation of a Component Model result type.
3434type result [Shape , OK , Err any ] struct {
3535 _ HostLayout
36- isErr bool
36+ isErr uint8
3737 _ [0 ]OK
3838 _ [0 ]Err
3939 data Shape // [unsafe.Sizeof(*(*Shape)(unsafe.Pointer(nil)))]byte
@@ -44,7 +44,7 @@ type result[Shape, OK, Err any] struct {
4444func 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 = ResultOK
47+ r .isErr = 0
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 {
5454func 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 = ResultErr
57+ r .isErr = 1
5858 * ((* Err )(unsafe .Pointer (& r .data ))) = err
5959 return R (r )
6060}
6161
6262// SetOK sets r to an OK result.
6363func (r * result [Shape , OK , Err ]) SetOK (ok OK ) {
6464 r .validate ()
65- r .isErr = ResultOK
65+ r .isErr = 0
6666 * ((* OK )(unsafe .Pointer (& r .data ))) = ok
6767}
6868
6969// SetErr sets r to an error result.
7070func (r * result [Shape , OK , Err ]) SetErr (err Err ) {
7171 r .validate ()
72- r .isErr = ResultErr
72+ r .isErr = 1
7373 * ((* Err )(unsafe .Pointer (& r .data ))) = err
7474}
7575
7676// IsOK returns true if r represents the OK case.
7777func (r * result [Shape , OK , Err ]) IsOK () bool {
7878 r .validate ()
79- return ! r .isErr
79+ return r .isErr == 0
8080}
8181
8282// IsErr returns true if r represents the error case.
8383func (r * result [Shape , OK , Err ]) IsErr () bool {
8484 r .validate ()
85- return r .isErr
85+ return r .isErr == 1
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.
9090func (r * result [Shape , OK , Err ]) OK () * OK {
9191 r .validate ()
92- if r .isErr {
92+ if r .isErr == 1 {
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.
100100func (r * result [Shape , OK , Err ]) Err () * Err {
101101 r .validate ()
102- if ! r .isErr {
102+ if r .isErr == 0 {
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.
111111func (r result [Shape , OK , Err ]) Result () (ok OK , err Err , isErr bool ) {
112- if r .isErr {
112+ if r .isErr == 1 {
113113 return ok , * (* Err )(unsafe .Pointer (& r .data )), true
114114 }
115115 return * (* OK )(unsafe .Pointer (& r .data )), err , false
0 commit comments