Documentation ¶
Index ¶
- type Result
- func (r Result[T]) Expect(msg string) T
- func (r Result[T]) ExpectErr(msg string) error
- func (r Result[T]) IsErr() bool
- func (r Result[T]) IsOk() bool
- func (r Result[T]) Unwrap() T
- func (r Result[T]) UnwrapErr() error
- func (r Result[T]) UnwrapOr(def T) T
- func (r Result[T]) UnwrapOrDefault() T
- func (r Result[T]) UnwrapOrElse(fn func(error) T) T
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 (Result[T]) Expect ¶
Expect panics with the given message if the Result is an error. Otherwise, it returns the value.
func (Result[T]) ExpectErr ¶
ExpectErr panics with the given message if the Result is ok. Otherwise, it returns the error.
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 ¶
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 ¶
UnwrapOrElse returns the value of the Result if it is ok. Otherwise, it returns the result of the given function.