result

package
v1.79.0-mod Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package result contains the Of result type, which is either a value or an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Of

type Of[T any] struct {
	// contains filtered or unexported fields
}

Of is either a T value or an error.

Think of it like Rust or Swift's result types. It's named "Of" because the fully qualified name for callers reads result.Of[T].

func Error

func Error[T any](err error) Of[T]

Error returns a new result with error err. If err is nil, the returned result is equivalent to calling Value with T's zero value.

func Value

func Value[T any](v T) Of[T]

Value returns a new result with value v, without an error.

func (Of[T]) Err

func (r Of[T]) Err() error

Err returns r's error, if any. When r.Err returns nil, it's safe to call r.MustValue without it panicking.

func (Of[T]) MustValue

func (r Of[T]) MustValue() T

MustValue returns r's result value. It panics if r.Err returns non-nil.

func (Of[T]) Value

func (r Of[T]) Value() (T, error)

Value returns r's result value and error.

Jump to

Keyboard shortcuts

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