Documentation
¶
Overview ¶
Package cm contains types and functions for interfacing with the WebAssembly Component Model.
The types in this package (such as List, Option, Result, and Variant) are designed to match the memory layout of Component Model types as specified in the Canonical ABI.
Index ¶
- Constants
- func BoolToU32[B ~bool](v B) uint32
- func Case[T any, V ~struct{ ... }, Tag Discriminant, Shape, Align any](v *V, tag Tag) *T
- func Err[R ~struct{ ... }, Shape, OK, Err any](err Err) R
- func F32ToU32(v float32) uint32
- func F64ToU64(v float64) uint64
- func LiftList[L List[T], T any, Data unsafe.Pointer | uintptr | *T, ...](data Data, len Len) L
- func LiftString[T ~string, Data unsafe.Pointer | uintptr | *uint8, ...](data Data, len Len) T
- func LowerList[L ~struct{ ... }, T any](list L) (*T, uint32)
- func LowerString[S ~string](s S) (*byte, uint32)
- func New[V ~struct{ ... }, Tag Discriminant, Shape, Align any, T any](tag Tag, data T) V
- func OK[R ~struct{ ... }, Shape, OK, Err any](ok OK) R
- func PointerToU32[T any](v *T) uint32
- func PointerToU64[T any](v *T) uint64
- func Reinterpret[T, From any](from From) (to T)
- func U32ToBool(v uint32) bool
- func U32ToF32(v uint32) float32
- func U32ToPointer[T any](v uint32) *T
- func U64ToF64(v uint64) float64
- func U64ToPointer[T any](v uint64) *T
- type BoolResult
- type Discriminant
- type List
- type Option
- type Rep
- type Resource
- type Result
- type Tuple
- type Tuple10
- type Tuple11
- type Tuple12
- type Tuple13
- type Tuple14
- type Tuple15
- type Tuple16
- type Tuple3
- type Tuple4
- type Tuple5
- type Tuple6
- type Tuple7
- type Tuple8
- type Tuple9
- type Variant
Constants ¶
const ( // ResultOK represents the OK case of a result. ResultOK = false // ResultErr represents the error case of a result. ResultErr = true )
const MaxTuple = 16
MaxTuple specifies the maximum number of fields in a Tuple* type, currently Tuple16. See https://github.com/WebAssembly/component-model/issues/373 for more information.
const ResourceNone = 0
ResourceNone is a sentinel value indicating a null or uninitialized resource. This is a reserved value specified in the Canonical ABI runtime state.
Variables ¶
This section is empty.
Functions ¶
func BoolToU32 ¶
BoolToU32 converts a value whose underlying type is bool into a uint32. Used to lower a bool into a Core WebAssembly i32 as specified in the Canonical ABI.
func Case ¶
func Case[T any, V ~struct{ variant[Tag, Shape, Align] }, Tag Discriminant, Shape, Align any](v *V, tag Tag) *T
Case returns a non-nil *T if the Variant case is equal to tag, otherwise it returns nil.
func Err ¶
func Err[R ~struct{ result[Shape, OK, Err] }, Shape, OK, Err any](err Err) 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 F32ToU32 ¶
F32ToU32 maps the bits of a float32 into a uint32. Used to lower a float32 into a Core WebAssembly i32 as specified in the Canonical ABI.
func F64ToU64 ¶
F64ToU64 maps the bits of a float64 into a uint64. Used to lower a float64 into a Core WebAssembly i64 as specified in the Canonical ABI.
func LiftList ¶
func LiftList[L List[T], T any, Data unsafe.Pointer | uintptr | *T, Len uint | uintptr | uint32 | uint64](data Data, len Len) L
LiftList lifts Core WebAssembly types into a List.
func LiftString ¶
func LiftString[T ~string, Data unsafe.Pointer | uintptr | *uint8, Len uint | uintptr | uint32 | uint64](data Data, len Len) T
LiftString lifts Core WebAssembly types into a [string].
func LowerString ¶
LowerString lowers a string into a pair of Core WebAssembly types.
func New ¶
func New[V ~struct{ variant[Tag, Shape, Align] }, Tag Discriminant, Shape, Align any, T any](tag Tag, data T) V
New returns a Variant with tag of type Disc, storage and GC shape of type Shape, aligned to type Align, with a value of type T.
func OK ¶
func OK[R ~struct{ result[Shape, OK, Err] }, Shape, OK, Err any](ok OK) R
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 PointerToU32 ¶
PointerToU32 converts a pointer of type *T into a uint32. Used to lower a pointer into a Core WebAssembly i32 as specified in the Canonical ABI.
func PointerToU64 ¶
PointerToU64 converts a pointer of type *T into a uint64. Used to lower a pointer into a Core WebAssembly i64 as specified in the Canonical ABI.
func Reinterpret ¶
func Reinterpret[T, From any](from From) (to T)
Reinterpret reinterprets the bits of type From into type T. Will panic if the size of From is smaller than the size of To.
func U32ToBool ¶
U32ToBool converts a uint32 into a bool. Used to lift a Core WebAssembly i32 into a bool as specified in the Canonical ABI.
func U32ToF32 ¶
U32ToF32 maps the bits of a uint32 into a float32. Used to lift a Core WebAssembly i32 into a float32 as specified in the Canonical ABI.
func U32ToPointer ¶
U32ToPointer converts a uint32 into a pointer of type *T. Used to lift a Core WebAssembly i32 into a pointer as specified in the Canonical ABI.
func U64ToF64 ¶
U64ToF64 maps the bits of a uint64 into a float64. Used to lift a Core WebAssembly i64 into a float64 as specified in the Canonical ABI.
func U64ToPointer ¶
U64ToPointer converts a uint64 into a pointer of type *T. Used to lift a Core WebAssembly i64 into a pointer as specified in the Canonical ABI.
Types ¶
type BoolResult ¶
type BoolResult bool
BoolResult represents a result with no OK or error type. False represents the OK case and true represents the error case.
type Discriminant ¶
Discriminant is the set of types that can represent the tag or discriminator of a variant. Use bool for 2-case variant types, result<T>, or option<T> types, uint8 where there are 256 or fewer cases, uint16 for up to 65,536 cases, or uint32 for anything greater.
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List represents a Component Model list. The binary representation of list<T> is similar to a Go slice minus the cap field.
func ToList ¶
ToList returns a List[T] equivalent to the Go slice s. The underlying slice data is not copied, and the resulting List points at the same array storage as the slice.
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option represents a Component Model option<T> type.
type Rep ¶
type Rep uint32
Rep represents a Component Model resource rep, the core representation type of a resource. It is represented in the Canonical ABI as an 32-bit integer.
type Resource ¶
type Resource uint32
Resource represents an opaque Component Model resource handle. It is represented in the Canonical ABI as an 32-bit integer.
type Result ¶
type Result[Shape, OK, Err any] struct { // contains filtered or unexported fields }
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.
func (*Result) Err ¶
func (r *Result) Err() *Err
Err returns a non-nil *Err pointer if r represents the error case. If r represents the OK case, then it returns nil.
type Tuple ¶
type Tuple[T0, T1 any] struct { F0 T0 F1 T1 }
Tuple represents a Component Model tuple with 2 fields.
type Tuple10 ¶
type Tuple10[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 F9 T9 }
Tuple10 represents a Component Model tuple with 10 fields.
type Tuple11 ¶
type Tuple11[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 F9 T9 F10 T10 }
Tuple11 represents a Component Model tuple with 11 fields.
type Tuple12 ¶
type Tuple12[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 F9 T9 F10 T10 F11 T11 }
Tuple12 represents a Component Model tuple with 12 fields.
type Tuple13 ¶
type Tuple13[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 F9 T9 F10 T10 F11 T11 F12 T12 }
Tuple13 represents a Component Model tuple with 13 fields.
type Tuple14 ¶
type Tuple14[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 F9 T9 F10 T10 F11 T11 F12 T12 F13 T13 }
Tuple14 represents a Component Model tuple with 14 fields.
type Tuple15 ¶
type Tuple15[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 F9 T9 F10 T10 F11 T11 F12 T12 F13 T13 F14 T14 }
Tuple15 represents a Component Model tuple with 15 fields.
type Tuple16 ¶
type Tuple16[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 F9 T9 F10 T10 F11 T11 F12 T12 F13 T13 F14 T14 F15 T15 }
Tuple16 represents a Component Model tuple with 16 fields.
type Tuple3 ¶
type Tuple3[T0, T1, T2 any] struct { F0 T0 F1 T1 F2 T2 }
Tuple3 represents a Component Model tuple with 3 fields.
type Tuple4 ¶
type Tuple4[T0, T1, T2, T3 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 }
Tuple4 represents a Component Model tuple with 4 fields.
type Tuple5 ¶
type Tuple5[T0, T1, T2, T3, T4 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 }
Tuple5 represents a Component Model tuple with 5 fields.
type Tuple6 ¶
type Tuple6[T0, T1, T2, T3, T4, T5 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 }
Tuple6 represents a Component Model tuple with 6 fields.
type Tuple7 ¶
type Tuple7[T0, T1, T2, T3, T4, T5, T6 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 }
Tuple7 represents a Component Model tuple with 7 fields.
type Tuple8 ¶
type Tuple8[T0, T1, T2, T3, T4, T5, T6, T7 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 }
Tuple8 represents a Component Model tuple with 8 fields.
type Tuple9 ¶
type Tuple9[T0, T1, T2, T3, T4, T5, T6, T7, T8 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 F6 T6 F7 T7 F8 T8 }
Tuple9 represents a Component Model tuple with 9 fields.
type Variant ¶
type Variant[Tag Discriminant, Shape, Align any] struct { // contains filtered or unexported fields }
Variant represents a loosely-typed Component Model variant. Shape and Align must be non-zero sized types. To create a variant with no associated types, use an enum.
func NewVariant ¶
func NewVariant[Tag Discriminant, Shape, Align any, T any](tag Tag, data T) Variant[Tag, Shape, Align]
NewVariant returns a Variant with tag of type Disc, storage and GC shape of type Shape, aligned to type Align, with a value of type T.