Documentation ¶
Overview ¶
Package result provides a Result type that can contain a value or an error.
Index ¶
- func Go[T any](f func() (T, error)) chan Result[T]
- type Result
- func Err[T any](err error) Result[T]
- func Errf[T any](format string, args ...interface{}) Result[T]
- func Errorf[T any](format string, args ...interface{}) Result[T]deprecated
- func From[T any](value T, err error) Result[T]
- func Ok[T any](value T) Result[T]
- func Outcome[T any](value T, err error) Result[T]deprecated
- func (r Result[T]) Default(value T) T
- func (r Result[T]) Err() error
- func (r Result[T]) Get() (T, bool)
- func (r Result[T]) GoString() string
- func (r Result[T]) MarshalJSON() ([]byte, error)
- func (r Result[T]) Result() (T, error)
- func (r Result[T]) String() string
- func (r *Result[T]) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
A Result type is a type that can contain an error or a value.
func From ¶ added in v0.14.0
From returns a Result that contains a value or an error.
It can be used to convert a function that returns a value and an error into a Result.
func (Result[T]) Default ¶
func (r Result[T]) Default(value T) T
Default returns the Result value if it is present, otherwise it returns the value passed.
func (Result[T]) MarshalJSON ¶
func (*Result[T]) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.