mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 12:33:42 +00:00
87a8aafc4f
- add internal/wasm-tools/go.mod file to depend on wasm-tools-go
- copy package cm into src/internal/cm
- remove wasm-tools-go "vendor" submodule
internal/tools: fix typo
go.{mod,sum}, internal/tools: add wit-bindgen-go to tools
GNUmakefile: use go run for wit-bindgen-go
GNUmakefile: add tools target to go:generate tools binaries in internal/tools
GNUmakefile: add .PHONY for lint and spell
GNUmakefile, internal/cm: vendor package cm into internal/cm
go.{mod,sum}: update wasm-tools-go to v0.1.4
internal/wasi: use internal/cm package
remove submodule src/vendor/github.com/ydnar/wasm-tools-go
GNUmakefile: add comment documenting what wasi-cm target does
go.{mod,sum}: remove toolchain; go mod tidy
go.mod: revert to Go 1.19
go.mod: go 1.19
go.{mod,sum}, internal/{tools,wasm-tools}: revert root go.mod file to go1.19
Create a wasm-tools specific module that can require go1.22 for wasm-tools-go.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package cm
|
|
|
|
// Option represents a Component Model [option<T>] type.
|
|
//
|
|
// [option<T>]: https://component-model.bytecodealliance.org/design/wit.html#options
|
|
type Option[T any] struct{ option[T] }
|
|
|
|
// None returns an [Option] representing the none case,
|
|
// equivalent to the zero value.
|
|
func None[T any]() Option[T] {
|
|
return Option[T]{}
|
|
}
|
|
|
|
// Some returns an [Option] representing the some case.
|
|
func Some[T any](v T) Option[T] {
|
|
return Option[T]{
|
|
option[T]{
|
|
isSome: true,
|
|
some: v,
|
|
},
|
|
}
|
|
}
|
|
|
|
// option represents the internal representation of a Component Model option type.
|
|
// The first byte is a bool representing none or some,
|
|
// followed by storage for the associated type T.
|
|
type option[T any] struct {
|
|
isSome bool
|
|
some T
|
|
}
|
|
|
|
// None returns true if o represents the none case.
|
|
func (o *option[T]) None() bool {
|
|
return !o.isSome
|
|
}
|
|
|
|
// Some returns a non-nil *T if o represents the some case,
|
|
// or nil if o represents the none case.
|
|
func (o *option[T]) Some() *T {
|
|
if o.isSome {
|
|
return &o.some
|
|
}
|
|
return nil
|
|
}
|