Documentation
¶
Index ¶
- func MapOr[T any, E error, U any](result Result[T, E], other U, f func(*T) U) U
- func MapOrElse[T any, E error, U any](result Result[T, E], def func(*E) U, f func(*T) U) U
- type Result
- func And[T any, E error, U any](result Result[T, E], other Result[U, E]) Result[U, E]
- func AndThen[T any, E error, U any](result Result[T, E], f func(*T) Result[U, E]) Result[U, E]
- func Err[T any, E error](err E) Result[T, E]
- func Map[T any, E error, U any](result Result[T, E], f func(*T) U) Result[U, E]
- func MapErr[T any, E error, F error](result Result[T, E], f func(*E) F) Result[T, F]
- func Ok[T any, E error](value T) Result[T, E]
- func Or[T any, E error, F error](result Result[T, E], other Result[T, F]) Result[T, F]
- func OrElse[T any, E error, F error](result Result[T, E], f func(*E) Result[T, F]) Result[T, F]
- func (result Result[_, E]) Err() option.Option[E]
- func (result Result[T, E]) Expect(message string) T
- func (result Result[T, E]) ExpectErr(message string) E
- func (result Result[T, E]) IsErr() bool
- func (result Result[T, E]) IsErrWith(f func(*E) bool) bool
- func (result Result[T, E]) IsOk() bool
- func (result Result[T, E]) IsOkWith(f func(*T) bool) bool
- func (result Result[T, _]) Ok() option.Option[T]
- func (result Result[T, E]) Unwrap() T
- func (result Result[T, E]) UnwrapErr() E
- func (result Result[T, E]) UnwrapOr(other T) T
- func (result Result[T, E]) UnwrapOrDefault() T
- func (result Result[T, E]) UnwrapOrElse(f func(*E) T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
This Result implementation is based on the one in the Rust's standart library (https://doc.rust-lang.org/stable/std/result/enum.Result.html) The Result represents the result of an operation that may either succeed (Ok) or fail (Err).
func AndThen ¶
Calls f if the result is Ok, otherwise returns the Err value of result. This function can be used for control flow based on Result values.
func Map ¶
Maps a Result[T, E] to Result[U, E] by applying a function to a contained Ok value, leaving an Err value untouched. This function can be used to compose the results of two functions.
func MapErr ¶
Maps a Result[T, E] to Result[T, F] by applying a function to a contained Err value, leaving an Ok value untouched. This function can be used to pass through a successful result while handling an error.
func Or ¶
Returns other if the result is Err, otherwise returns the Ok value of result. Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else, which is lazily evaluated.
func OrElse ¶
Calls f if the result is Err, otherwise returns the Ok value of result. This function can be used for control flow based on result values.
func (Result[_, E]) Err ¶
Converts from Result[T, E] to Option[E]. Converts result into an Option[E], consuming the error, and discarding the value, if any.
func (Result[T, E]) Expect ¶
Returns the contained Ok value, consuming the self value. Panics if the value is an Err, with a panic message including the passed message, and the content of the Err.
func (Result[T, E]) ExpectErr ¶
Returns the contained Err value, consuming the self value. Panics if the value is an Ok, with a panic message including the passed message, and the content of the Ok.
func (Result[T, E]) IsErrWith ¶
Returns true if the result is Err wrapping an error matching the predicate.
func (Result[T, E]) IsOkWith ¶
Returns true if the result is Ok wrapping a value matching the predicate.
func (Result[T, _]) Ok ¶
Converts from Result[T, E] to Option[T]. Converts result into an Option[T], consuming the result value, and discarding the error, if any.
func (Result[T, E]) Unwrap ¶
func (result Result[T, E]) Unwrap() T
Returns the contained Ok value, consuming the self value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the Err case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default. Panics if the value is an Err, with a panic message provided by the Err’s value.
func (Result[T, E]) UnwrapErr ¶
func (result Result[T, E]) UnwrapErr() E
Returns the contained Err value, consuming the self value. Panics if the value is an Ok, with a custom panic message provided by the Ok’s value.
func (Result[T, E]) UnwrapOr ¶
func (result Result[T, E]) UnwrapOr(other T) T
Returns the contained Ok value or a provided default. Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.
func (Result[T, E]) UnwrapOrDefault ¶
func (result Result[T, E]) UnwrapOrDefault() T
Returns the contained Ok value or a default Consumes the self argument then, if Ok, returns the contained value, otherwise if Err, returns the default value for that type.
func (Result[T, E]) UnwrapOrElse ¶
func (result Result[T, E]) UnwrapOrElse(f func(*E) T) T
Returns the contained Ok value or computes it from a closure.