result

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

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

Result represents failure or success. The Ok variant represents success and contains a value. The Err variant represent a failure and contains an error.

func Err

func Err[T any](err error) Result[T]

Err instanitates a failed result with an error.

func Ok

func Ok[T any](value T) Result[T]

Ok instanriates a successful result with a value.

func (Result[T]) IsErr

func (r Result[T]) IsErr() bool

IsErr returns true if the Result is an Err variant.

func (Result[T]) IsOk

func (r Result[T]) IsOk() bool

IsOk returns true if the Result is an Ok variant.

func (Result[T]) String

func (r Result[T]) String() string

func (Result[T]) Unwrap

func (r Result[T]) Unwrap() T

Unwrap returns the underlying value of an Ok variant, or panics if called on an Err variant.

func (Result[T]) UnwrapOr

func (r Result[T]) UnwrapOr(value T) T

UnwrapOr returns the underlying value of an Ok variant, or the provided value on an Err variant.

func (Result[T]) UnwrapOrElse

func (r Result[T]) UnwrapOrElse(f func() T) T

UnwrapOrElse returns the underlying value of an Ok variant, or the result of calling the provided function on an Err variant.

func (Result[T]) UnwrapOrZero

func (r Result[T]) UnwrapOrZero() T

UnwrapOrZero returns the underlying value of an Ok variant, or the zero value of an Err variant.

func (Result[T]) Value

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

Value returns the underlying value and nil for an Ok variant, or the zero value and an error for an Error variant.

Jump to

Keyboard shortcuts

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