std/go
On this page
Index
- type
Error- method
Error.display - method
Error.message - method
Error.go_type
- method
- type
Any- method
Any.display - method
Any.type_name - method
Any.is_nil - method
Any.as_int - method
Any.as_float - method
Any.as_bool - method
Any.as_str - method
Any.as_bytes - method
Any.as_list - method
Any.as_map - method
Any.as_handle
- method
- type
Out - type
Recv- method
Recv.recv - method
Recv.try_recv - method
Recv.each
- method
- fn
error - fn
any - fn
out
Types
Error
struct Error {}An error returned by a Go function: the error of a Go (T, error)
result, which a binding maps to T ! go.Error. Its text is captured at
the boundary, so display performs no Go call.
Error.display
fn (e: Error) display() -> StrThe Go error’s Error() text.
Error.message
fn (e: Error) message() -> StrThe Go error’s Error() text (same as display).
Error.go_type
fn (e: Error) go_type() -> StrThe Go dynamic type of the error, for example *url.Error.
Any
struct Any {}A Go any (interface{}) value a use go binding takes or returns
(decision 0412): opaque to Xo. Make one with go.any(x) (a list
literal written for a ...any parameter converts its elements
implicitly); read one with the as_* methods, None on another Go
type. Compares as Go’s == on the interface. A value a replay rebuilt
only displays, unless its function is replay rerun (core 11.3).
Any.display
fn (a: Any) display() -> StrThe value as Go’s %v.
Any.type_name
fn (a: Any) type_name() -> StrThe value’s Go type, as Go’s %T (int, *sql.Rows, <nil>).
Any.is_nil
fn (a: Any) is_nil() -> BoolWhether the value is Go’s nil, or a nil pointer, slice or map.
Any.as_int
fn (a: Any) as_int() -> Int?The value as an Int when it is one of Go’s integer types and fits.
Any.as_float
fn (a: Any) as_float() -> Float?The value as a Float when it is a float64 or float32.
Any.as_bool
fn (a: Any) as_bool() -> Bool?The value as a Bool when it is one.
Any.as_str
fn (a: Any) as_str() -> Str?The value as a Str when its Go kind is string.
Any.as_bytes
fn (a: Any) as_bytes() -> Bytes?The value as Bytes when it is a []byte (copied).
Any.as_list
fn (a: Any) as_list() -> List[Any]?The elements of a Go slice or array.
Any.as_map
fn (a: Any) as_map() -> Map[Str, Any]?The entries of a Go map with string keys.
Any.as_handle
fn (a: Any) as_handle[T]() -> T?The use go handle of type T that holds the value, when the value’s
Go type is T’s.
Out
struct Out[T] {}A Go pointer a Go function fills through any (rows.scan,
json.unmarshal): pass .any(), read .get() after the call.
Out.any
fn (o: Out[T]) any() -> AnyThe pointer, as the go.Any the Go function takes.
Out.get
fn (o: Out[T]) get() -> TThe value Go wrote; a fault when Go wrote another type.
Recv
struct Recv[T] {}A Go channel Xo receives from (decision 0421): a <-chan T or
chan T a Go function, field or variable gives Xo. Sending and
closing are Go’s; a nil Go channel is a closed one.
Recv.recv
fn (r: Recv[T]) recv() -> T? uses goThe next value; None once the channel is closed and empty. Waits in
Go: a cancellation point (the task’s cancellation or
task.with_timeout ends the wait).
Recv.try_recv
fn (r: Recv[T]) try_recv() -> T?? uses goThe next value if one is ready: None when none is, Some(None) once the channel is closed.
Recv.each
fn (r: Recv[T]) each[fx: Effects](f: fn(T) uses fx) uses go, fxCalls f with each value until the channel is closed.
Functions
error
fn error(message: Str) -> ErrorA Go error with text message (Go’s errors.New), for an Xo
function a Go library calls to return (decision 0416): an Xo
callback’s ! go.Error is the callback’s Go error. An Error that
came from Go goes back as that Go error, so Go’s errors.Is sees it.
any
fn any[T](x: T) -> AnyAn Xo value as the Go value a binding passes for it: Int as int64, Float as float64, Str as string, Bytes as []byte, Duration as time.Duration, Time as time.Time, a handle as its Go value, a List as a slice, a Map as a map, an Option as its value or nil.
out
fn out[T]() -> Out[T]A new Go pointer to the zero value of T’s Go type (T a value type
go.any takes, a handle, or go.Any).