result

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 0 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 is a generic type that represents the result of an operation that can fail. It is either Ok(value) or Error(err).

func Error

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

Error creates a new Result with the given error.

func Ok

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

Ok creates a new Result with the given value.

func (Result[T]) Expect

func (r Result[T]) Expect(msg string) T

Expect panics with the given message if the Result is an error. Otherwise, it returns the value.

func (Result[T]) ExpectErr

func (r Result[T]) ExpectErr(msg string) error

ExpectErr panics with the given message if the Result is ok. Otherwise, it returns the error.

func (Result[T]) IsErr

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

IsErr returns true if the Result is an error.

func (Result[T]) IsOk

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

IsOk returns true if the Result is ok.

func (Result[T]) Unwrap

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

Unwrap returns the value of the Result if it is ok. It panics if the Result is an error.

func (Result[T]) UnwrapErr

func (r Result[T]) UnwrapErr() error

UnwrapErr returns the error of the Result if it is an error. It panics if the Result is ok.

func (Result[T]) UnwrapOr

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

UnwrapOr returns the value of the Result if it is ok. Otherwise, it returns the given default value.

func (Result[T]) UnwrapOrDefault

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

UnwrapOrDefault returns the value of the Result if it is ok. Otherwise, it returns the zero value of the type.

func (Result[T]) UnwrapOrElse

func (r Result[T]) UnwrapOrElse(fn func(error) T) T

UnwrapOrElse returns the value of the Result if it is ok. Otherwise, it returns the result of the given function.

Jump to

Keyboard shortcuts

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