witgo

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const MaxTuple = 8

MaxTuple is the longest tuple witgo has a type for.

Variables

This section is empty.

Functions

func Bool

func Bool(v component.Value) (bool, error)

Bool reads a bool.

func Char

func Char(v component.Value) (rune, error)

Char reads a char.

func ErrorContextOf

func ErrorContextOf(v component.Value) (*component.ErrorContext, error)

ErrorContextOf reads an error-context an import received or an export returned.

func F32

func F32(v component.Value) (float32, error)

F32 reads an f32.

func F64

func F64(v component.Value) (float64, error)

F64 reads an f64.

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 LowerUnit

func LowerUnit(struct{}) component.Value

LowerUnit writes a bare stream's or future's element.

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

func ResultValue(v component.Value, wit string) (component.ResultValue, error)

ResultValue reads a result.

func S8

func S8(v component.Value) (int8, error)

S8 reads an s8, which lifts as an int32.

func S16

func S16(v component.Value) (int16, error)

S16 reads an s16, which lifts as an int32.

func S32

func S32(v component.Value) (int32, error)

S32 reads an s32.

func S64

func S64(v component.Value) (int64, error)

S64 reads an s64.

func String

func String(v component.Value) (string, error)

String reads a string.

func U8

func U8(v component.Value) (uint8, error)

U8 reads a u8, which lifts as a uint32.

func U16

func U16(v component.Value) (uint16, error)

U16 reads a u16, which lifts as a uint32.

func U32

func U32(v component.Value) (uint32, error)

U32 reads a u32, and an enum's case, a flags value or a resource handle, which lift as one.

func U64

func U64(v component.Value) (uint64, error)

U64 reads a u64.

func Unit

func Unit(component.Value) (struct{}, error)

Unit reads a bare stream's or future's element, which has no value.

func Values

func Values(v component.Value, n int, wit string) ([]component.Value, error)

Values reads a list, record or tuple that lifts as a []component.Value, checking its length when n is not negative.

func Variant

func Variant(v component.Value, wit string) (component.VariantValue, error)

Variant reads a variant.

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

func NewAsync[T any](call *component.AsyncCall, lower func(T) []component.Value) Async[T]

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.

func (Async[T]) OnCancel

func (a Async[T]) OnCancel(fn func())

OnCancel registers fn to run if the guest cancels the call.

func (Async[T]) Return

func (a Async[T]) Return(v T)

Return completes the call with v. It may be called once.

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]) Close

func (f *FutureReader[T]) Close()

Close drops the reader.

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

func (h *Handles) Mint(tag, rep uint32, borrow bool) component.Value

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.

func (*Handles) Release

func (h *Handles) Release() error

Release drops the handles minted for borrows. It does not run the resources' destructors: the host still owns them.

func (*Handles) Rep

func (h *Handles) Rep(tag uint32, own bool, v component.Value) (uint32, error)

Rep reads the handle v of the host resource tag, returning its rep: taking the handle out of the table for an own, leaving it for a borrow.

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.

func (*Pending[T]) Await

func (p *Pending[T]) Await(ctx context.Context) (T, error)

Await drives the call until it returns, and gives its result.

func (*Pending[T]) Cancel

func (p *Pending[T]) Cancel(ctx context.Context) error

Cancel asks the guest to cancel the call.

func (*Pending[T]) Done

func (p *Pending[T]) Done() <-chan struct{}

Done is closed once the call has returned.

type Result

type Result[T, E any] struct {
	Ok    T
	Err   E
	IsErr bool
}

Result is WIT's result<T, E>. An arm WIT leaves out is struct{}.

func Err

func Err[T, E any](e E) Result[T, E]

Err is a Result holding e as its error arm.

func Ok

func Ok[T, E any](v T) Result[T, E]

Ok is a Result holding v as its ok arm.

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.

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
}

Tuple2 to Tuple8 are WIT's tuples, their elements in order.

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
}

Tuple2 to Tuple8 are WIT's tuples, their elements in order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL