aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/internal/cm/result.go
diff options
context:
space:
mode:
authorRandy Reddig <[email protected]>2024-10-17 08:08:21 -0700
committerRon Evans <[email protected]>2024-10-17 17:30:33 +0100
commitd5f195387d14ba48f977841d7b3d38459604cc5d (patch)
tree330077cac0871a248398aff7fd813c7f51f57d53 /src/internal/cm/result.go
parenta0d4ecb607478c9981673cd86716a535e4f6df15 (diff)
downloadtinygo-d5f195387d14ba48f977841d7b3d38459604cc5d.tar.gz
tinygo-d5f195387d14ba48f977841d7b3d38459604cc5d.zip
internal/{cm,wasi}: regenerate WASI 0.2 bindings with wasm-tools-go v0.3.0
Diffstat (limited to 'src/internal/cm/result.go')
-rw-r--r--src/internal/cm/result.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/internal/cm/result.go b/src/internal/cm/result.go
index d21275612..82200e278 100644
--- a/src/internal/cm/result.go
+++ b/src/internal/cm/result.go
@@ -17,10 +17,22 @@ type BoolResult bool
// Result represents a result sized to hold the Shape type.
// The size of the Shape type must be greater than or equal to the size of OK and Err types.
// For results with two zero-length types, use [BoolResult].
-type Result[Shape, OK, Err any] struct{ result[Shape, OK, Err] }
+type Result[Shape, OK, Err any] struct {
+ _ HostLayout
+ result[Shape, OK, Err]
+}
+
+// AnyResult is a type constraint for generic functions that accept any [Result] type.
+type AnyResult[Shape, OK, Err any] interface {
+ ~struct {
+ _ HostLayout
+ result[Shape, OK, Err]
+ }
+}
// result represents the internal representation of a Component Model result type.
type result[Shape, OK, Err any] struct {
+ _ HostLayout
isErr bool
_ [0]OK
_ [0]Err
@@ -88,8 +100,8 @@ func (r *result[Shape, OK, Err]) validate() {
// OK returns an OK result with shape Shape and type OK and Err.
// Pass Result[OK, OK, Err] or Result[Err, OK, Err] as the first type argument.
-func OK[R ~struct{ result[Shape, OK, Err] }, Shape, OK, Err any](ok OK) R {
- var r struct{ result[Shape, OK, Err] }
+func OK[R AnyResult[Shape, OK, Err], Shape, OK, Err any](ok OK) R {
+ var r Result[Shape, OK, Err]
r.validate()
r.isErr = ResultOK
*((*OK)(unsafe.Pointer(&r.data))) = ok
@@ -98,8 +110,8 @@ func OK[R ~struct{ result[Shape, OK, Err] }, Shape, OK, Err any](ok OK) R {
// Err returns an error result with shape Shape and type OK and Err.
// Pass Result[OK, OK, Err] or Result[Err, OK, Err] as the first type argument.
-func Err[R ~struct{ result[Shape, OK, Err] }, Shape, OK, Err any](err Err) R {
- var r struct{ result[Shape, OK, Err] }
+func Err[R AnyResult[Shape, OK, Err], Shape, OK, Err any](err Err) R {
+ var r Result[Shape, OK, Err]
r.validate()
r.isErr = ResultErr
*((*Err)(unsafe.Pointer(&r.data))) = err