Documentation
¶
Overview ¶
Package witgo holds the types and conversions that Go bindings generated by wazy-bindgen (see package bindgen) are written in terms of: WIT's result and tuple types, and the reading of a component.Value into the Go type a WIT primitive maps to.
Index ¶
- Constants
- func Bool(v component.Value) (bool, error)
- func Char(v component.Value) (rune, error)
- func ErrorContextOf(v component.Value) (*component.ErrorContext, error)
- func F32(v component.Value) (float32, error)
- func F64(v component.Value) (float64, error)
- func LowerErrorContext(e *component.ErrorContext) component.Value
- func LowerUnit(struct{}) component.Value
- func NewFuture[T any](inst *component.Instance, elem *component.TypeRef, resolve component.Resolver, ...) (*FutureWriter[T], *FutureReader[T], error)
- func NewStream[T any](inst *component.Instance, elem *component.TypeRef, resolve component.Resolver, ...) (*StreamWriter[T], *StreamReader[T], error)
- func ResultValue(v component.Value, wit string) (component.ResultValue, error)
- func S8(v component.Value) (int8, error)
- func S16(v component.Value) (int16, error)
- func S32(v component.Value) (int32, error)
- func S64(v component.Value) (int64, error)
- func String(v component.Value) (string, error)
- func U8(v component.Value) (uint8, error)
- func U16(v component.Value) (uint16, error)
- func U32(v component.Value) (uint32, error)
- func U64(v component.Value) (uint64, error)
- func Unit(component.Value) (struct{}, error)
- func Values(v component.Value, n int, wit string) ([]component.Value, error)
- func Variant(v component.Value, wit string) (component.VariantValue, error)
- type Async
- type FutureReader
- type FutureWriter
- type Handles
- type Pending
- type Result
- type StreamReader
- type StreamWriter
- type Tuple2
- type Tuple3
- type Tuple4
- type Tuple5
- type Tuple6
- type Tuple7
- type Tuple8
Constants ¶
const MaxTuple = 8
MaxTuple is the longest tuple witgo has a type for.
Variables ¶
This section is empty.
Functions ¶
func ErrorContextOf ¶
func ErrorContextOf(v component.Value) (*component.ErrorContext, error)
ErrorContextOf reads an error-context an import received or an export returned.
func LowerErrorContext ¶
func LowerErrorContext(e *component.ErrorContext) component.Value
LowerErrorContext writes e, which is nil for a nil e: the engine then refuses it, rather than passing an error context with no message.
func NewFuture ¶
func NewFuture[T any](inst *component.Instance, elem *component.TypeRef, resolve component.Resolver, lift func(component.Value) (T, error), lower func(T) component.Value) (*FutureWriter[T], *FutureReader[T], error)
NewFuture is NewStream for a future<T>.
func NewStream ¶
func NewStream[T any](inst *component.Instance, elem *component.TypeRef, resolve component.Resolver, lift func(component.Value) (T, error), lower func(T) component.Value) (*StreamWriter[T], *StreamReader[T], error)
NewStream makes a stream<T> of inst's, whose element type elem resolve resolves (nil for a bare stream), converting its values with lift and lower.
func ResultValue ¶
ResultValue reads a result.
func U32 ¶
U32 reads a u32, and an enum's case, a flags value or a resource handle, which lift as one.
Types ¶
type Async ¶
type Async[T any] struct { // contains filtered or unexported fields }
Async completes one call of an async import: the host may return its result before the import function returns, or later -- from another goroutine, when the call was started with CallAsync.
func NewAsync ¶
NewAsync is the Async generated code hands an async import's host function, lowering its result with lower.
func (Async[T]) Cancelled ¶
func (a Async[T]) Cancelled()
Cancelled completes the call as cancelled, once the guest has asked to cancel it (see OnCancel).
func (Async[T]) Defer ¶
func (a Async[T]) Defer(fn func())
Defer runs fn on the instance's scheduler, where Return may be called without CallAsync.
type FutureReader ¶
type FutureReader[T any] struct { // contains filtered or unexported fields }
FutureReader is the readable end of a WIT future<T>; see StreamReader.
func FutureReaderOf ¶
func FutureReaderOf[T any](v component.Value, lift func(component.Value) (T, error)) (*FutureReader[T], error)
FutureReaderOf is ReaderOf for a future.
func (*FutureReader[T]) Cancel ¶
func (f *FutureReader[T]) Cancel()
Cancel revokes a pending Get, which then completes as CopyCancelled.
func (*FutureReader[T]) Get ¶
func (f *FutureReader[T]) Get(onDone func(res component.CopyResult, v T, err error))
Get reads the future's value, once it is set. onDone gets CopyDropped, and no value, if the writer closed it unset.
func (*FutureReader[T]) Raw ¶
func (f *FutureReader[T]) Raw() component.Value
Raw is the untyped reader, which the bindings pass to the engine. It is nil for a nil f.
type FutureWriter ¶
type FutureWriter[T any] struct { // contains filtered or unexported fields }
FutureWriter is the host's writable end of a future<T>, made with its reader by NewFuture.
func (*FutureWriter[T]) Close ¶
func (f *FutureWriter[T]) Close()
Close drops the writer, which may only follow a completed Set.
func (*FutureWriter[T]) Set ¶
func (f *FutureWriter[T]) Set(v T, onDone func(res component.CopyResult))
Set sets the future's value. onDone runs once the reader has it, or as CopyDropped if the reader closed first.
type Handles ¶
type Handles struct {
// Table is the handle table the handles live in.
Table *component.HandleTable
// Inst is the instance a guest resource's handle belongs to.
Inst *component.Instance
// contains filtered or unexported fields
}
Handles moves resource handles between a component's handle table and the reps the host works with, for the handles the engine does not translate itself: those nested in an import's composite arguments and results, and every one an export takes or returns.
func (*Handles) Mint ¶
Mint puts rep, a host resource of tag, in the table and returns the handle. One minted for a borrow is dropped again by Release, once the call that borrows it has returned.
type Pending ¶
type Pending[T any] struct { // contains filtered or unexported fields }
Pending is an async export call in flight, started with CallAsync.
func NewPending ¶
func NewPending[T any](p *component.PendingCall, lift func([]component.Value) (T, error)) *Pending[T]
NewPending is the Pending generated code returns, lifting the call's results with lift.
type StreamReader ¶
type StreamReader[T any] struct { // contains filtered or unexported fields }
StreamReader is the readable end of a WIT stream<T>, which is how the bindings pass every stream: an import's argument or result, an export's argument or result. The host reads one it was given, or hands one to the guest, after which it is the guest's.
Its operations follow component.StreamReader's: they run on the instance's scheduler, and complete through a callback.
func ReaderOf ¶
func ReaderOf[T any](v component.Value, lift func(component.Value) (T, error)) (*StreamReader[T], error)
ReaderOf is the StreamReader the bindings lift from v, a stream an import received or an export returned, as a *component.StreamReader.
func (*StreamReader[T]) Cancel ¶
func (s *StreamReader[T]) Cancel()
Cancel revokes a pending Read, which then completes as CopyCancelled.
func (*StreamReader[T]) Close ¶
func (s *StreamReader[T]) Close()
Close drops the reader: the writer's pending and later writes complete as CopyDropped.
func (*StreamReader[T]) Raw ¶
func (s *StreamReader[T]) Raw() component.Value
Raw is the untyped reader, which the bindings pass to the engine. It is nil for a nil s.
func (*StreamReader[T]) Read ¶
func (s *StreamReader[T]) Read(n uint32, onDone func(res component.CopyResult, vals []T, err error))
Read reads up to n values. onDone gets what was read, and how the read ended: CopyDropped once the writer has closed the stream.
func (*StreamReader[T]) ReadAll ¶
func (s *StreamReader[T]) ReadAll(chunk uint32, onDone func(vals []T, err error))
ReadAll reads until the writer closes the stream, chunk values at a time, and gives onDone everything read. A read cancelled first ends it with an error.
type StreamWriter ¶
type StreamWriter[T any] struct { // contains filtered or unexported fields }
StreamWriter is the host's writable end of a stream<T>, made with its reader by NewStream.
func (*StreamWriter[T]) Cancel ¶
func (s *StreamWriter[T]) Cancel()
Cancel revokes a pending Write, which then completes as CopyCancelled.
func (*StreamWriter[T]) Close ¶
func (s *StreamWriter[T]) Close()
Close ends the stream: the reader's pending and later reads complete as CopyDropped.
func (*StreamWriter[T]) Write ¶
func (s *StreamWriter[T]) Write(vals []T, onDone func(res component.CopyResult, n uint32))
Write offers vals to the stream. onDone gets how many the reader took, and how the write ended: CopyDropped once the reader has closed the stream. One write may be pending at a time.
func (*StreamWriter[T]) WriteAll ¶
func (s *StreamWriter[T]) WriteAll(vals []T, onDone func(n int, res component.CopyResult))
WriteAll writes every value of vals, as the reader takes them, and gives onDone how many it took and how the last write ended.
type Tuple2 ¶
type Tuple2[T0, T1 any] struct { F0 T0 F1 T1 }
Tuple2 to Tuple8 are WIT's tuples, their elements in order.
type Tuple3 ¶
type Tuple3[T0, T1, T2 any] struct { F0 T0 F1 T1 F2 T2 }
Tuple2 to Tuple8 are WIT's tuples, their elements in order.
type Tuple4 ¶
type Tuple4[T0, T1, T2, T3 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 }
Tuple2 to Tuple8 are WIT's tuples, their elements in order.
type Tuple5 ¶
type Tuple5[T0, T1, T2, T3, T4 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 }
Tuple2 to Tuple8 are WIT's tuples, their elements in order.
type Tuple6 ¶
type Tuple6[T0, T1, T2, T3, T4, T5 any] struct { F0 T0 F1 T1 F2 T2 F3 T3 F4 T4 F5 T5 }
Tuple2 to Tuple8 are WIT's tuples, their elements in order.