Documentation
¶
Overview ¶
Package wit contains a Go representation of the WIT (WebAssembly Interface Type) specification as defined in the WebAssembly Component Model.
Structure ¶
A fully-decoded Resolve struct is a cyclical data structure containing World, Interface, and TypeDef values that reference each other. Tools to decode polymorphic, cyclical JSON are implemented in the codec package. Types defined in this package largely map 1:1 to their equivalent types in the wit-parser crate (source), accommodating differences between the Go and Rust type systems.
Types that are represented as Rust enums are implemented via sealed Go interfaces, implemented by other types in this package. An example is WorldItem, which is the set of types that a World may import or export, currently InterfaceRef, TypeDef, and Function.
JSON ¶
DecodeJSON decodes fully-resolved WIT descriptions in JSON format generated by wasm-tools into a Resolve:
f, err := os.Open("wasi-clocks.wit.json") if err != nil { return err } defer f.Close() res, err := wit.DecodeJSON(f) if err != nil { return err } // Do something with res
Index ¶
- Constants
- func Align(ptr, align uintptr) uintptr
- func HasBorrow(t TypeDefKind) bool
- func HasPointer(t TypeDefKind) bool
- func HasResource(t TypeDefKind) bool
- func KindOf[K TypeDefKind](t Type) (kind K)
- type ABI
- type Bool
- type Borrow
- type Case
- type Char
- type Constructor
- type Direction
- type Docs
- type Enum
- type EnumCase
- type F32
- type F64
- type Field
- type Flag
- type Flags
- type Freestanding
- type Function
- func (f *Function) BaseName() string
- func (f *Function) CoreFunction(op Direction) *Function
- func (f *Function) DecodeField(dec codec.Decoder, name string) error
- func (f *Function) IsAdmin() bool
- func (f *Function) IsConstructor() bool
- func (f *Function) IsFreestanding() bool
- func (f *Function) IsMethod() bool
- func (f *Function) IsStatic() bool
- func (f *Function) PostReturn(dir Direction) *Function
- func (f *Function) ReturnsBorrow() bool
- func (f *Function) ReturnsPointer() bool
- func (f *Function) Type() Type
- func (f *Function) WIT(ctx Node, name string) string
- func (f *Function) WITKind() string
- type FunctionKind
- type Future
- type Handle
- type Ident
- type Interface
- type InterfaceRef
- type List
- type Method
- type Node
- type Option
- type Own
- type Package
- type Param
- type Pointer
- type Primitive
- type Record
- type Resolve
- type Resource
- type Result
- func (r *Result) Align() uintptr
- func (r *Result) DecodeField(dec codec.Decoder, name string) error
- func (r *Result) Despecialize() TypeDefKind
- func (r *Result) Flat() []Type
- func (r *Result) Size() uintptr
- func (r *Result) Types() []Type
- func (r *Result) WIT(_ Node, name string) string
- func (*Result) WITKind() string
- type S16
- type S32
- type S64
- type S8
- type Stability
- type Stable
- type Static
- type Stream
- type String
- type Tuple
- func (t *Tuple) Align() uintptr
- func (t *Tuple) DecodeField(dec codec.Decoder, name string) error
- func (t *Tuple) Despecialize() TypeDefKind
- func (t *Tuple) Flat() []Type
- func (t *Tuple) Size() uintptr
- func (t *Tuple) Type() Type
- func (t *Tuple) WIT(ctx Node, name string) string
- func (*Tuple) WITKind() string
- type Type
- type TypeDef
- func (t *TypeDef) Align() uintptr
- func (t *TypeDef) Constructor() *Function
- func (t *TypeDef) Destructor() *Function
- func (t *TypeDef) Flat() []Type
- func (t *TypeDef) Methods() []*Function
- func (t *TypeDef) ResourceDrop() *Function
- func (t *TypeDef) ResourceNew() *Function
- func (t *TypeDef) ResourceRep() *Function
- func (t *TypeDef) Root() *TypeDef
- func (t *TypeDef) Size() uintptr
- func (t *TypeDef) StaticFunctions() []*Function
- func (t *TypeDef) TypeName() string
- func (t *TypeDef) WIT(ctx Node, name string) string
- func (t *TypeDef) WITKind() string
- type TypeDefKind
- type TypeOwner
- type U16
- type U32
- type U64
- type U8
- type Unstable
- type Variant
- func (v *Variant) Align() uintptr
- func (v *Variant) DecodeField(dec codec.Decoder, name string) error
- func (v *Variant) Enum() *Enum
- func (v *Variant) Flat() []Type
- func (v *Variant) Size() uintptr
- func (v *Variant) Types() []Type
- func (v *Variant) WIT(ctx Node, name string) string
- func (*Variant) WITKind() string
- type World
- type WorldItem
Constants ¶
const ( // MaxFlatParams is the maximum number of [flattened parameters] a function can have // as defined in the Component Model Canonical ABI. // // [flattened parameters]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#flattening MaxFlatParams = 16 // MaxFlatResults is the maximum number of [flattened results] a function can have // as defined in the Component Model Canonical ABI. // // [flattened results]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#flattening MaxFlatResults = 1 )
const ( DocPrefix = "///" LineLength = 80 )
Variables ¶
This section is empty.
Functions ¶
func HasBorrow ¶
func HasBorrow(t TypeDefKind) bool
HasBorrow returns whether or not t contains a Borrow type.
func HasPointer ¶
func HasPointer(t TypeDefKind) bool
HasPointer returns whether or not t contains a Type with a pointer, e.g. String or List.
func HasResource ¶
func HasResource(t TypeDefKind) bool
HasResource returns whether or not t contains a resource type, typically an Own or Borrow handle.
func KindOf ¶
func KindOf[K TypeDefKind](t Type) (kind K)
KindOf probes Type t to determine if it is a TypeDef with TypeDefKind K. It returns the underlying Kind if present.
Types ¶
type ABI ¶
ABI is the interface implemented by any type that can report its Canonical ABI size, alignment, and flat representation.
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool represents the WIT primitive type bool, a boolean value either true or false. It is equivalent to the Go type bool. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (Bool) Align ¶
func (Bool) Align() uintptr
Align returns the byte alignment for values of this type.
func (Bool) Flat ¶
func (Bool) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (Bool) WITKind ¶
func (Bool) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type Borrow ¶
type Borrow struct { Type *TypeDef // contains filtered or unexported fields }
Borrow represents a WIT borrowed handle. It implements the Handle, Node, ABI, and TypeDefKind interfaces.
func (Borrow) Align ¶
func (Borrow) Align() uintptr
Align returns the ABI byte alignment for this Handle.
func (Borrow) Flat ¶
func (Borrow) Flat() []Type
Flat returns the flattened ABI representation of this type.
type Case ¶
Case represents a single case in a Variant. It implements the Node interface.
func (*Case) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type Char ¶
type Char struct {
// contains filtered or unexported fields
}
Char represents the WIT primitive type char, a single Unicode character, specifically a Unicode scalar value. It is equivalent to the Go type rune. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (Char) Align ¶
func (Char) Align() uintptr
Align returns the byte alignment for values of this type.
func (Char) Flat ¶
func (Char) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (Char) WITKind ¶
func (Char) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type Constructor ¶
type Constructor struct { Type Type // contains filtered or unexported fields }
Constructor represents a function that is a constructor for its associated Type.
type Direction ¶
type Direction int
Direction represents the direction a type or function is represented within a component, whether it is an importer (consumer), or an exporter (producer). When applied to functions, this represents the Canonical ABI lift and lower operations, for lowering into or lifting out of linear memory.
const ( // Exported represents types and functions imported into a component from the host or another component. // This corresponds to the the Canonical ABI [lower] operation, lowering Component Model types into linear memory. // Used for calling functions imported using //go:wasmimport. // // [lower]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#canon-lower Imported Direction = 0 // Exported represents types and functions exported from a component to the host or another component. // This corresponds to the Canonical ABI [lift] operation, lifting Component Model types out of linear memory. // Used for exporting functions using //go:wasmexport. // // [lift]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#canon-lift Exported Direction = 1 )
type Docs ¶
type Docs struct {
Contents string // may be empty
}
Docs represent WIT documentation text extracted from comments.
func (*Docs) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type Enum ¶
type Enum struct { Cases []EnumCase // contains filtered or unexported fields }
Enum represents a WIT enum type, which is a Variant without associated data. The equivalent in Go is a set of const identifiers declared with iota. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Enum) Align ¶
Align returns the ABI byte alignment for Enum e. It is first despecialized into a Variant with no associated types, then aligned.
func (*Enum) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
func (*Enum) Despecialize ¶
func (e *Enum) Despecialize() TypeDefKind
Despecialize despecializes Enum e into a Variant with no associated types. See the canonical ABI documentation for more information.
func (*Enum) Size ¶
Size returns the ABI byte size for Enum e, the smallest integer type that can represent 0...len(e.Cases). It is first despecialized into a Variant with no associated types, then sized.
type EnumCase ¶
EnumCase represents a single case in an Enum. It implements the Node interface.
func (*EnumCase) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type F32 ¶
type F32 struct {
// contains filtered or unexported fields
}
F32 represents the WIT primitive type f32, a 32-bit floating point value. It is equivalent to the Go type float32. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (F32) Align ¶
func (F32) Align() uintptr
Align returns the byte alignment for values of this type.
func (F32) Flat ¶
func (F32) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (F32) WITKind ¶
func (F32) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type F64 ¶
type F64 struct {
// contains filtered or unexported fields
}
F64 represents the WIT primitive type f64, a 64-bit floating point value. It is equivalent to the Go type float64. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (F64) Align ¶
func (F64) Align() uintptr
Align returns the byte alignment for values of this type.
func (F64) Flat ¶
func (F64) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (F64) WITKind ¶
func (F64) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type Field ¶
Field represents a field in a Record.
func (*Field) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type Flag ¶
Flag represents a single flag value in a Flags type. It implements the Node interface.
func (*Flag) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type Flags ¶
type Flags struct { Flags []Flag // contains filtered or unexported fields }
Flags represents a WIT flags type, stored as a bitfield. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Flags) Align ¶
Align returns the ABI byte alignment of Flags f.
func (*Flags) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type Freestanding ¶
type Freestanding struct {
// contains filtered or unexported fields
}
Freestanding represents a free-standing function that is not a method, static, or a constructor.
type Function ¶
type Function struct { Name string Kind FunctionKind Params []Param // arguments to the function Results []Param // a function can have a single anonymous result, or > 1 named results Stability Stability // WIT @since or @unstable (nil if unknown) Docs Docs // contains filtered or unexported fields }
Function represents a WIT function. Functions can be freestanding, methods, constructors or static. It implements the Node and WorldItem interfaces.
func LiftFunction ¶
LiftFunction returns a Function signature for lifting Type t.
func LowerFunction ¶
LowerFunction returns a Function signature for lowering Type t.
func (*Function) BaseName ¶
BaseName returns the base name of Function f. For static functions, this returns the function name unchanged. For constructors, this removes the [constructor] and type prefix. For static functions, this removes the [static] and type prefix. For methods, this removes the [method] and type prefix. For special functions like [resource-drop], it will return a well-known value.
func (*Function) CoreFunction ¶
CoreFunction returns a Core WebAssembly function of Function f. Its params and results may be flattened according to the Canonical ABI specification. The flattening rules vary based on whether the returned function is imported or exported, e.g. using go:wasmimport or go:wasmexport.
func (*Function) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
func (*Function) IsAdmin ¶
IsAdmin returns true if Function f is an administrative function in the Canonical ABI.
func (*Function) IsConstructor ¶
IsConstructor returns true if Function f is a constructor. To qualify, it must have a *Constructor Kind with a non-nil type.
func (*Function) IsFreestanding ¶
IsFreestanding returns true if Function f is a freestanding function, and not a constructor, method, or static function.
func (*Function) IsMethod ¶
IsMethod returns true if Function f is a method. To qualify, it must have a *Method Kind with a non-nil Type which matches borrow<t> of its first param.
func (*Function) IsStatic ¶
IsStatic returns true if Function f is a static function. To qualify, it must have a *Static Kind with a non-nil type.
func (*Function) PostReturn ¶
PostReturn returns a post-return function for f, which is part of the Component Model machinery that allows the caller of f to call back into the component to clean up results. Returns nil if the Core WebAssembly derivative of f has no results, therefore does not require cleanup.
While this accepts a Direction, this is currently only used for exported functions.
func (*Function) ReturnsBorrow ¶
ReturnsBorrow reports whether Function f returns a Borrow handle, which is not permitted by the Component Model specification.
func (*Function) ReturnsPointer ¶
ReturnsPointer reports whether Function f returns a value containing a pointer, which would require a post-return cleanup function if exported.
func (*Function) Type ¶
Type returns the associated (self) Type for Function f, if f is a constructor, method, or static function. If f is a freestanding function, this returns nil.
type FunctionKind ¶
type FunctionKind interface {
// contains filtered or unexported methods
}
FunctionKind represents the kind of a WIT function, which can be one of Freestanding, Method, Static, or Constructor.
type Future ¶
type Future struct { Type Type // optional associated Type (can be nil) // contains filtered or unexported fields }
Future represents a WIT future type, expected to be part of WASI Preview 3. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Future) Align ¶
Align returns the ABI byte alignment a Future. TODO: what is the ABI alignment of a future?
func (*Future) Flat ¶
Flat returns the flattened ABI representation of Future. TODO: what is the ABI representation of a stream?
func (*Future) Size ¶
Size returns the ABI byte size for a Future. TODO: what is the ABI size of a future?
type Handle ¶
type Handle interface { TypeDefKind // contains filtered or unexported methods }
Handle represents a WIT handle type. It conforms to the Node, ABI, and TypeDefKind interfaces. Handles represent the passing of unique ownership of a resource between two components. When the owner of an owned handle drops that handle, the resource is destroyed. In contrast, a borrowed handle represents a temporary loan of a handle from the caller to the callee for the duration of the call.
type Ident ¶
type Ident struct { // Namespace specifies the package namespace, such as "wasi" in "wasi:foo/bar". Namespace string // Package specifies the name of the package. Package string // Extension optionally specifies a world or interface name. Extension string // Version optionally specifies version information. Version *semver.Version }
Ident represents a Component Model identifier for a Package, World, or Interface, such as wasi:clocks@0.2.0 or wasi:clocks/wall-clock@0.2.0.
A Ident contains a namespace and package name, along with an optional extension and SemVer version.
func ParseIdent ¶
ParseIdent parses a WIT identifier string into an Ident, returning any errors encountered. The resulting Ident may not be valid.
func (*Ident) DecodeString ¶
DecodeString implements the codec.StringDecoder interface to decode a string value into an Ident.
func (*Ident) String ¶
String implements fmt.Stringer, returning the canonical string representation of an Ident.
func (*Ident) UnversionedString ¶
UnversionedString returns a string representation of an Ident without version information.
type Interface ¶
type Interface struct { Name *string TypeDefs ordered.Map[string, *TypeDef] Functions ordered.Map[string, *Function] Package *Package // the Package this Interface belongs to Stability Stability // WIT @since or @unstable (nil if unknown) Docs Docs // contains filtered or unexported fields }
An Interface represents a collection of types and functions, which are imported into or exported from a WebAssembly component. It implements the Node, and TypeOwner interfaces.
func (*Interface) AllFunctions ¶
AllFunctions returns a sequence that yields each Function in an Interface. The sequence stops if yield returns false.
type InterfaceRef ¶
type InterfaceRef struct { Interface *Interface Stability Stability // contains filtered or unexported fields }
An InterfaceRef represents a reference to an Interface with a Stability attribute. It implements the Node and WorldItem interfaces.
func (*InterfaceRef) WIT ¶
func (ref *InterfaceRef) WIT(ctx Node, name string) string
WIT returns the WIT text format for InterfaceRef i.
type List ¶
type List struct { Type Type // contains filtered or unexported fields }
List represents a WIT list type, which is an ordered vector of an arbitrary type. It implements the Node, ABI, and TypeDefKind interfaces.
type Method ¶
type Method struct { Type Type // contains filtered or unexported fields }
Method represents a function that is a method on its associated Type. The first argument to the function is self, an instance of Type.
type Node ¶
type Node interface { // WITKind returns the human-readable WIT kind this Node represents, e.g. "type" or "function". WITKind() string // WIT returns the WIT text format for a Node in a given context, which may be nil. WIT(ctx Node, name string) string }
Node is the common interface implemented by the WIT (WebAssembly Interface Type) types in this package.
type Option ¶
type Option struct { Type Type // contains filtered or unexported fields }
Option represents a WIT option type, a special case of Variant. An Option can contain a value of a single type, either build-in or user defined, or no value. The equivalent in Go for an option<string> could be represented as *string. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Option) Align ¶
Align returns the ABI byte alignment for Option o. It is first despecialized into a Variant with two cases, "none" and "some(T)", then aligned.
func (*Option) Despecialize ¶
func (o *Option) Despecialize() TypeDefKind
Despecialize despecializes Option o into a Variant with two cases, "none" and "some". See the canonical ABI documentation for more information.
func (*Option) Size ¶
Size returns the ABI byte size for Option o. It is first despecialized into a Variant with two cases, "none" and "some(T)", then sized.
type Own ¶
type Own struct { Type *TypeDef // contains filtered or unexported fields }
Own represents an WIT owned handle. It implements the Handle, Node, ABI, and TypeDefKind interfaces.
func (Own) Flat ¶
func (Own) Flat() []Type
Flat returns the flattened ABI representation of this type.
type Package ¶
type Package struct { Name Ident Interfaces ordered.Map[string, *Interface] Worlds ordered.Map[string, *World] Docs Docs }
Package represents a WIT package within a Resolve. It implements the Node interface.
A Package is a collection of Interface and World values. Additionally, a Package contains a unique identifier that affects generated components and uniquely identifies this particular package.
type Param ¶
Param represents a parameter to or the result of a Function. A Param can be unnamed.
func (*Param) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type Pointer ¶
type Pointer struct { Type Type // contains filtered or unexported fields }
Pointer represents a pointer to a WIT type. It is only used for ABI representation, e.g. pointers to function parameters or return values.
func (*Pointer) Align ¶
Align returns the ABI byte alignment for Pointer.
type Primitive ¶
type Primitive interface { Type // contains filtered or unexported methods }
Primitive is the interface implemented by WIT primitive types. It also conforms to the Node, ABI, Type, and TypeDefKind interfaces.
type Record ¶
type Record struct { Fields []Field // contains filtered or unexported fields }
Record represents a WIT record type, akin to a struct. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Record) Align ¶
Align returns the ABI byte alignment for Record r.
func (*Record) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
type Resolve ¶
type Resolve struct { Worlds []*World Interfaces []*Interface TypeDefs []*TypeDef Packages []*Package }
Resolve represents a fully resolved set of WIT (WebAssembly Interface Type) packages and worlds. It implements the Node interface.
This structure contains a graph of WIT packages and their contents merged together into slices organized by type. Items are sorted topologically and everything is fully resolved.
Each World, Interface, TypeDef, or Package in a Resolve must be non-nil.
func DecodeJSON ¶
DecodeJSON decodes JSON from r into a Resolve struct. It returns any error that may occur during decoding.
func LoadJSON ¶
LoadJSON loads a WIT JSON file from path. If path is "" or "-", it reads from os.Stdin.
func LoadWIT ¶
LoadWIT loads WIT data from path by processing it through wasm-tools. This will fail if wasm-tools is not in $PATH. If path is "" or "-", it reads from os.Stdin.
func ParseWIT ¶ added in v0.2.3
ParseWIT parses WIT data from a buffer by processing it through wasm-tools. This will fail if wasm-tools is not in $PATH.
func (*Resolve) AllFunctions ¶
AllFunctions returns a sequence that yields each Function in a Resolve. The sequence stops if yield returns false.
func (*Resolve) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
func (*Resolve) ResolveCodec ¶
ResolveCodec implements the codec.Resolver interface translating types to decoding/encoding-aware versions.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource represents a WIT resource type. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Resource) Align ¶
Align returns the ABI byte alignment for Resource.
func (*Resource) Size ¶
Size returns the ABI byte size for Resource.
type Result ¶
type Result struct { OK Type // optional associated [Type] (can be nil) Err Type // optional associated [Type] (can be nil) // contains filtered or unexported fields }
Result represents a WIT result type, which is the result of a function call, returning an optional value and/or an optional error. It is roughly equivalent to the Go pattern of returning (T, error). It implements the Node, ABI, and TypeDefKind interfaces.
func (*Result) Align ¶
Align returns the ABI byte alignment for Result r. It is first despecialized into a Variant with two cases "ok" and "error", then aligned.
func (*Result) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
func (*Result) Despecialize ¶
func (r *Result) Despecialize() TypeDefKind
Despecialize despecializes Result o into a Variant with two cases, "ok" and "error". See the canonical ABI documentation for more information.
func (*Result) Size ¶
Size returns the ABI byte size for Result r. It is first despecialized into a Variant with two cases "ok" and "error", then sized.
type S16 ¶
type S16 struct {
// contains filtered or unexported fields
}
S16 represents the WIT primitive type s16, a signed 16-bit integer. It is equivalent to the Go type int16. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (S16) Align ¶
func (S16) Align() uintptr
Align returns the byte alignment for values of this type.
func (S16) Flat ¶
func (S16) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (S16) WITKind ¶
func (S16) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type S32 ¶
type S32 struct {
// contains filtered or unexported fields
}
S32 represents the WIT primitive type s32, a signed 32-bit integer. It is equivalent to the Go type int32. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (S32) Align ¶
func (S32) Align() uintptr
Align returns the byte alignment for values of this type.
func (S32) Flat ¶
func (S32) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (S32) WITKind ¶
func (S32) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type S64 ¶
type S64 struct {
// contains filtered or unexported fields
}
S64 represents the WIT primitive type s64, a signed 64-bit integer. It is equivalent to the Go type int64. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (S64) Align ¶
func (S64) Align() uintptr
Align returns the byte alignment for values of this type.
func (S64) Flat ¶
func (S64) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (S64) WITKind ¶
func (S64) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type S8 ¶
type S8 struct {
// contains filtered or unexported fields
}
S8 represents the WIT primitive type s8, a signed 8-bit integer. It is equivalent to the Go type int8. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (S8) Align ¶
func (S8) Align() uintptr
Align returns the byte alignment for values of this type.
func (S8) Flat ¶
func (S8) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (S8) WITKind ¶
func (S8) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type Stability ¶
type Stability interface { Node // contains filtered or unexported methods }
Stability represents the version or feature-gated stability of a given feature.
type Stable ¶
type Stable struct { Since semver.Version Deprecated *semver.Version // contains filtered or unexported fields }
Stable represents a stable WIT feature, for example: @since(version = 1.2.3)
Stable features have an explicit since version and an optional feature name.
type Static ¶
type Static struct { Type Type // contains filtered or unexported fields }
Static represents a function that is a static method of its associated Type.
type Stream ¶
type Stream struct { Element Type // optional associated Type (can be nil) End Type // optional associated Type (can be nil) // contains filtered or unexported fields }
Stream represents a WIT stream type, expected to be part of WASI Preview 3. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Stream) Align ¶
Align returns the ABI byte alignment a Stream. TODO: what is the ABI alignment of a stream?
func (*Stream) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
func (*Stream) Flat ¶
Flat returns the flattened ABI representation of Stream. TODO: what is the ABI representation of a stream?
func (*Stream) Size ¶
Size returns the ABI byte size for a Stream. TODO: what is the ABI size of a stream?
type String ¶
type String struct {
// contains filtered or unexported fields
}
String represents the WIT primitive type string, a finite string of Unicode characters. It is equivalent to the Go type string. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (String) Align ¶
func (String) Align() uintptr
Align returns the byte alignment for values of this type.
func (String) Flat ¶
func (String) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (String) Size ¶
func (String) Size() uintptr
Size returns the byte size for values of this type.
func (String) WITKind ¶
func (String) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type Tuple ¶
type Tuple struct { Types []Type // contains filtered or unexported fields }
Tuple represents a WIT tuple type. A tuple type is an ordered fixed length sequence of values of specified types. It is similar to a Record, except that the fields are identified by their order instead of by names. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Tuple) Align ¶
Align returns the ABI byte alignment for Tuple t. It is first despecialized into a Record with 0-based integer field names, then aligned.
func (*Tuple) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
func (*Tuple) Despecialize ¶
func (t *Tuple) Despecialize() TypeDefKind
Despecialize despecializes Tuple e into a Record with 0-based integer field names. See the canonical ABI documentation for more information.
func (*Tuple) Size ¶
Size returns the ABI byte size for Tuple t. It is first despecialized into a Record with 0-based integer field names, then sized.
func (*Tuple) Type ¶
Type returns a non-nil Type if all types in t are the same. Returns nil if t contains more than one type.
type Type ¶
type Type interface { TypeDefKind TypeName() string // contains filtered or unexported methods }
Type is the interface implemented by any type definition. This can be a primitive type or a user-defined type in a TypeDef. It also conforms to the Node, ABI, and TypeDefKind interfaces.
func Discriminant ¶
Discriminant returns the smallest WIT integer type that can represent 0...n. Used by the Canonical ABI for Variant types.
type TypeDef ¶
type TypeDef struct { Name *string Kind TypeDefKind Owner TypeOwner Stability Stability // WIT @since or @unstable (nil if unknown) Docs Docs // contains filtered or unexported fields }
TypeDef represents a WIT type definition. A TypeDef may be named or anonymous, and optionally belong to a World or Interface. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (*TypeDef) Constructor ¶
Constructor returns the constructor for TypeDef t, or nil if none. Currently t must be a Resource to have a constructor.
func (*TypeDef) Destructor ¶
Destructor returns the implied destructor (dtor) method for t. If t is not a Resource, this returns nil.
func (*TypeDef) Methods ¶
Methods returns all methods for TypeDef t. Currently t must be a Resource to have methods.
func (*TypeDef) ResourceDrop ¶
ResourceDrop returns the implied resource-drop method for t. If t is not a Resource, this returns nil.
func (*TypeDef) ResourceNew ¶
ResourceNew returns the implied resource-new function for t. If t is not a Resource, this returns nil.
func (*TypeDef) ResourceRep ¶
ResourceRep returns the implied resource-rep method for t. If t is not a Resource, this returns nil.
func (*TypeDef) Root ¶
Root returns the root TypeDef of type alias t. If t is not a type alias, Root returns t.
func (*TypeDef) StaticFunctions ¶
StaticFunctions returns all static functions for TypeDef t. Currently t must be a Resource to have static functions.
func (*TypeDef) TypeName ¶
TypeName returns the WIT type name for t. Returns an empty string if t is anonymous.
type TypeDefKind ¶
TypeDefKind represents the underlying type in a TypeDef, which can be one of Record, Resource, Handle, Flags, Tuple, Variant, Enum, Option, Result, List, Future, Stream, or Type. It implements the Node and ABI interfaces.
func Despecialize ¶
func Despecialize(k TypeDefKind) TypeDefKind
Despecialize despecializes k if k can be despecialized. Otherwise, it returns k unmodified. See the canonical ABI documentation for more information.
type TypeOwner ¶
type TypeOwner interface { Node AllFunctions() iterate.Seq[*Function] WITPackage() *Package // contains filtered or unexported methods }
TypeOwner is the interface implemented by any type that can own a TypeDef, currently World and Interface.
type U16 ¶
type U16 struct {
// contains filtered or unexported fields
}
U16 represents the WIT primitive type u16, an unsigned 16-bit integer. It is equivalent to the Go type uint16. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (U16) Align ¶
func (U16) Align() uintptr
Align returns the byte alignment for values of this type.
func (U16) Flat ¶
func (U16) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (U16) WITKind ¶
func (U16) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type U32 ¶
type U32 struct {
// contains filtered or unexported fields
}
U32 represents the WIT primitive type u32, an unsigned 32-bit integer. It is equivalent to the Go type uint32. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (U32) Align ¶
func (U32) Align() uintptr
Align returns the byte alignment for values of this type.
func (U32) Flat ¶
func (U32) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (U32) WITKind ¶
func (U32) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type U64 ¶
type U64 struct {
// contains filtered or unexported fields
}
U64 represents the WIT primitive type u64, an unsigned 64-bit integer. It is equivalent to the Go type uint64. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (U64) Align ¶
func (U64) Align() uintptr
Align returns the byte alignment for values of this type.
func (U64) Flat ¶
func (U64) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (U64) WITKind ¶
func (U64) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type U8 ¶
type U8 struct {
// contains filtered or unexported fields
}
U8 represents the WIT primitive type u8, an unsigned 8-bit integer. It is equivalent to the Go type uint8. It implements the Node, ABI, Type, and TypeDefKind interfaces.
func (U8) Align ¶
func (U8) Align() uintptr
Align returns the byte alignment for values of this type.
func (U8) Flat ¶
func (U8) Flat() []Type
Flat returns the flattened ABI representation of this type.
func (U8) WITKind ¶
func (U8) WITKind() string
WITKind returns the canonical primitive type kind in WIT text format.
type Unstable ¶
type Unstable struct { Feature string Deprecated *semver.Version // contains filtered or unexported fields }
Unstable represents an unstable WIT feature defined by name.
type Variant ¶
type Variant struct { Cases []Case // contains filtered or unexported fields }
Variant represents a WIT variant type, a tagged/discriminated union. A variant type declares one or more cases. Each case has a name and, optionally, a type of data associated with that case. It implements the Node, ABI, and TypeDefKind interfaces.
func (*Variant) Align ¶
Align returns the ABI byte alignment for Variant v.
func (*Variant) DecodeField ¶
DecodeField implements the codec.FieldDecoder interface to decode a struct or JSON object.
func (*Variant) Enum ¶
Enum attempts to represent Variant v as an Enum. This will only succeed if v has no associated types. If v has associated types, then it will return nil.
func (*Variant) Size ¶
Size returns the ABI byte size for Variant v.
type World ¶
type World struct { Name string Imports ordered.Map[string, WorldItem] Exports ordered.Map[string, WorldItem] Package *Package // the Package this World belongs to (must be non-nil) Stability Stability // WIT @since or @unstable (nil if unknown) Docs Docs // contains filtered or unexported fields }
A World represents all of the imports and exports of a WebAssembly component. It implements the Node and TypeOwner interfaces.
func (*World) AllFunctions ¶
AllFunctions returns a sequence that yields each Function in a World. The sequence stops if yield returns false.