core

package
v1.20.7 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToError

func ToError(r VoidResult) error

ToError converts VoidResult to a standard Go error. Returns nil if IsOk() is true, otherwise returns the error.

Example:

```go
import "github.com/andeya/gust/result"
var res result.VoidResult = result.RetVoid(err)
if err := result.ToError(res); err != nil {
	return err
}
```

func UnwrapErrOr

func UnwrapErrOr(r VoidResult, def error) error

UnwrapErrOr returns the contained error value or a provided default for VoidResult.

Example:

```go
import "github.com/andeya/gust/result"
var res result.VoidResult = result.RetVoid(err)
err := result.UnwrapErrOr(res, errors.New("default error"))
```

Types

type Option

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

Option can be used to avoid `(T, bool)` and `if *U != nil`, represents an optional value:

every [`Option`] is either [`Some`](which is non-none T), or [`None`](which is none).

func AssertOpt

func AssertOpt[T any](i any) Option[T]

AssertOpt returns the Option[T] of asserting `i` to type `T`

func BoolAssertOpt

func BoolAssertOpt[T any](i any, ok bool) Option[T]

BoolAssertOpt wraps a value as an Option. NOTE:

`ok=true` is wrapped as Some,
and `ok=false` is wrapped as None.

func BoolOpt

func BoolOpt[T any](value T, ok bool) Option[T]

BoolOpt wraps a value as an Option. NOTE:

`ok=true` is wrapped as Some,
and `ok=false` is wrapped as None.

func ElemOpt

func ElemOpt[T any](ptr *T) Option[T]

ElemOpt wraps a value from pointer. NOTE:

`non-nil pointer` is wrapped as Some,
and `nil pointer` is wrapped as None.

func None

func None[T any]() Option[T]

None returns a none. NOTE:

Option[T].IsNone() returns true,
and Option[T].IsSome() returns false.

func PtrOpt

func PtrOpt[U any, T *U](ptr T) Option[T]

PtrOpt wraps a pointer value. NOTE:

`non-nil pointer` is wrapped as Some,
and `nil pointer` is wrapped as None.

func RetAnyOpt

func RetAnyOpt[T any](value any, err error) Option[any]

RetAnyOpt wraps a value as an `Option[any]`. NOTE:

`err != nil` or `value`==nil is wrapped as None,
and `err == nil` and `value != nil` is wrapped as Some.

func RetOpt

func RetOpt[T any](value T, err error) Option[T]

RetOpt wraps a value as an `Option[T]`. NOTE:

`err != nil` is wrapped as None,
and `err == nil` is wrapped as Some.

func Some

func Some[T any](value T) Option[T]

Some wraps a non-none value. NOTE:

Option[T].IsSome() returns true.
and Option[T].IsNone() returns false.

func ZeroOpt

func ZeroOpt[T comparable](value T) Option[T]

ZeroOpt wraps a value as an Option. NOTE:

`non-zero T` is wrapped as Some,
and `zero T` is wrapped as None.

func (Option[T]) And

func (o Option[T]) And(optb Option[T]) Option[T]

And returns [`None`] if the option is [`None`], otherwise returns `optb`.

func (Option[T]) AndThen

func (o Option[T]) AndThen(f func(T) Option[T]) Option[T]

AndThen returns [`None`] if the option is [`None`], otherwise calls `f` with the

func (*Option[T]) AsPtr

func (o *Option[T]) AsPtr() *T

AsPtr returns its pointer or nil.

func (Option[T]) Expect

func (o Option[T]) Expect(msg string) T

Expect returns the contained [`Some`] value. Panics if the value is none with a custom panic message provided by `msg`.

func (Option[T]) Filter

func (o Option[T]) Filter(predicate func(T) bool) Option[T]

Filter returns [`None`] if the option is [`None`], otherwise calls `predicate` with the wrapped value and returns.

func (*Option[T]) GetOrInsert

func (o *Option[T]) GetOrInsert(some T) *T

GetOrInsert inserts `value` into the option if it is [`None`], then returns the contained value pointer.

func (*Option[T]) GetOrInsertDefault

func (o *Option[T]) GetOrInsertDefault() *T

GetOrInsertDefault inserts default value into the option if it is [`None`], then returns the contained value pointer.

func (*Option[T]) GetOrInsertWith

func (o *Option[T]) GetOrInsertWith(f func() T) *T

GetOrInsertWith inserts a value computed from `f` into the option if it is [`None`], then returns the contained value.

func (*Option[T]) Insert

func (o *Option[T]) Insert(some T) *T

Insert inserts `value` into the option, then returns its pointer.

func (Option[T]) Inspect

func (o Option[T]) Inspect(f func(T)) Option[T]

Inspect calls the provided closure with a reference to the contained value (if it has value).

func (Option[T]) InspectNone

func (o Option[T]) InspectNone(f func()) Option[T]

InspectNone calls the provided closure (if it is none).

func (Option[T]) IsNone

func (o Option[T]) IsNone() bool

IsNone returns `true` if the option is none.

func (Option[T]) IsSome

func (o Option[T]) IsSome() bool

IsSome returns `true` if the option has value.

func (Option[T]) IsSomeAnd

func (o Option[T]) IsSomeAnd(f func(T) bool) bool

IsSomeAnd returns `true` if the option has value and the value inside it matches a predicate.

func (Option[T]) Map

func (o Option[T]) Map(f func(T) T) Option[T]

Map maps an `Option[T]` to `Option[T]` by applying a function to a contained value.

func (Option[T]) MapOr

func (o Option[T]) MapOr(defaultSome T, f func(T) T) T

MapOr returns the provided default value (if none), or applies a function to the contained value (if any).

func (Option[T]) MapOrElse

func (o Option[T]) MapOrElse(defaultFn func() T, f func(T) T) T

MapOrElse computes a default function value (if none), or applies a different function to the contained value (if any).

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Option[T]) Next

func (o *Option[T]) Next() Option[T]

Next returns the next element of the iterator.

func (*Option[T]) NextBack

func (o *Option[T]) NextBack() Option[T]

NextBack returns the next element from the back of the iterator.

func (Option[T]) OkOr

func (o Option[T]) OkOr(err any) Result[T]

OkOr transforms the `Option[T]` into a [`Result[T]`], mapping [`Some(v)`] to [`Ok(v)`] and [`None`] to [`Err(err)`].

func (Option[T]) OkOrElse

func (o Option[T]) OkOrElse(errFn func() any) Result[T]

OkOrElse transforms the `Option[T]` into a [`Result[T]`], mapping [`Some(v)`] to [`Ok(v)`] and [`None`] to [`Err(errFn())`].

func (Option[T]) Or

func (o Option[T]) Or(optb Option[T]) Option[T]

Or returns the option if it contains a value, otherwise returns `optb`.

func (Option[T]) OrElse

func (o Option[T]) OrElse(f func() Option[T]) Option[T]

OrElse returns the option if it contains a value, otherwise calls `f` and returns the result.

func (Option[T]) Ref

func (o Option[T]) Ref() *Option[T]

Ref returns the pointer of the object.

func (*Option[T]) Remaining

func (o *Option[T]) Remaining() uint

Remaining returns the number of remaining elements in the iterator.

func (*Option[T]) Replace

func (o *Option[T]) Replace(some T) (old Option[T])

Replace replaces the actual value in the option by the value given in parameter, returning the old value if present, leaving a [`Some`] in its place without deinitializing either one.

func (*Option[T]) SizeHint

func (o *Option[T]) SizeHint() (uint, Option[uint])

SizeHint returns a hint about the remaining size of the iterator.

func (Option[T]) Split

func (o Option[T]) Split() (T, bool)

Split returns the tuple (T, bool).

func (Option[T]) String

func (o Option[T]) String() string

String returns the string representation.

func (*Option[T]) Take

func (o *Option[T]) Take() Option[T]

Take takes the value out of the option, leaving a [`None`] in its place.

func (Option[T]) ToResult

func (o Option[T]) ToResult() VoidResult

ToResult converts from `Option[T]` to `VoidResult` (Result[Void]). If Option is Some, returns Err[Void] with the value wrapped in errutil.ErrBox. If Option is None, returns Ok[Void](nil).

Example:

```go
import "github.com/andeya/gust/option"
import "github.com/andeya/gust/result"
var opt option.Option[string] = option.Some("value")
var res result.VoidResult = opt.ToResult()
```

func (Option[T]) ToX

func (o Option[T]) ToX() Option[any]

ToX converts to `Option[any]`.

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Option[T]) Unwrap

func (o Option[T]) Unwrap() T

Unwrap returns the contained value. Panics if the value is none.

func (Option[T]) UnwrapOr

func (o Option[T]) UnwrapOr(fallbackValue T) T

UnwrapOr returns the contained value or a provided fallback value.

func (Option[T]) UnwrapOrDefault

func (o Option[T]) UnwrapOrDefault() T

UnwrapOrDefault returns the contained value or a non-nil-pointer zero value.

func (Option[T]) UnwrapOrElse

func (o Option[T]) UnwrapOrElse(defaultSome func() T) T

UnwrapOrElse returns the contained value or computes it from a closure.

func (Option[T]) UnwrapOrThrow

func (r Option[T]) UnwrapOrThrow(err any) T

UnwrapOrThrow returns the contained T or panic returns error interface. NOTE:

If there is an error, that panic should be caught with `Result.Catch()`

func (Option[T]) UnwrapUnchecked

func (o Option[T]) UnwrapUnchecked() T

UnwrapUnchecked returns the contained value.

func (Option[T]) XAnd

func (o Option[T]) XAnd(optb Option[any]) Option[any]

XAnd returns [`None`] if the option is [`None`], otherwise returns `optb`.

func (Option[T]) XAndThen

func (o Option[T]) XAndThen(f func(T) Option[any]) Option[any]

XAndThen returns [`None`] if the option is [`None`], otherwise calls `f` with the

func (Option[T]) XMap

func (o Option[T]) XMap(f func(T) any) Option[any]

XMap maps an `Option[T]` to `Option[any]` by applying a function to a contained value.

func (Option[T]) XMapOr

func (o Option[T]) XMapOr(defaultSome any, f func(T) any) any

XMapOr returns the provided default value (if none), or applies a function to the contained value (if any).

func (Option[T]) XMapOrElse

func (o Option[T]) XMapOrElse(defaultFn func() any, f func(T) any) any

XMapOrElse computes a default function value (if none), or applies a different function to the contained value (if any).

func (Option[T]) XOkOr

func (o Option[T]) XOkOr(err any) Result[any]

XOkOr transforms the `Option[T]` into a [`Result[any]`], mapping [`Some(v)`] to [`Ok(v)`] and [`None`] to [`Err(err)`].

func (Option[T]) XOkOrElse

func (o Option[T]) XOkOrElse(errFn func() any) Result[any]

XOkOrElse transforms the `Option[T]` into a [`Result[any]`], mapping [`Some(v)`] to [`Ok(v)`] and [`None`] to [`Err(errFn())`].

func (Option[T]) Xor

func (o Option[T]) Xor(optb Option[T]) Option[T]

Xor [`Some`] if exactly one of `self`, `optb` is [`Some`], otherwise returns [`None`].

type Result

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

Result can be used to improve `func()(T,error)`, represents either success (T) or failure (error).

func AssertRet

func AssertRet[T any](i any) Result[T]

AssertRet returns the Result[T] of asserting `i` to type `T`

func FmtErr

func FmtErr[T any](format string, a ...any) Result[T]

FmtErr wraps a failure result with a formatted error.

func Ok

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

Ok wraps a successful result.

func Ret

func Ret[T any](some T, err error) Result[T]

Ret wraps a result.

func TryErr

func TryErr[T any](err any) Result[T]

TryErr wraps a failure result. NOTE: If err is nil, TryErr(nil) returns Ok with zero value. This follows the principle that nil represents "no error", so TryErr(nil) should be Ok.

Example:

```go
import "github.com/andeya/gust/result"
res := result.TryErr[string](nil)  // This is an ok state
if res.IsOk() {
	fmt.Println("This will be printed")
}
```

func (Result[T]) And

func (r Result[T]) And(r2 Result[T]) Result[T]

And returns `r` if `r` is `Err`, otherwise returns `r2`.

func (Result[T]) And2

func (r Result[T]) And2(v2 T, err2 error) Result[T]

And2 returns `r` if `r` is `Err`, otherwise returns `Ret(v2, err2)`.

func (Result[T]) AndThen

func (r Result[T]) AndThen(op func(T) Result[T]) Result[T]

AndThen calls op if the result is Ok, otherwise returns the error of self. This function can be used for control flow based on Result values.

Example
package main

import (
	"fmt"

	"github.com/andeya/gust/internal/core"
)

func main() {
	var divide = func(i, j float32) core.Result[float32] {
		if j == 0 {
			return core.TryErr[float32]("j can not be 0")
		}
		return core.Ok(i / j)
	}
	var ret float32 = divide(1, 2).AndThen(func(i float32) core.Result[float32] {
		return core.Ok(i * 10)
	}).Unwrap()
	fmt.Println(ret)
}
Output:
5

func (Result[T]) AndThen2

func (r Result[T]) AndThen2(op func(T) (T, error)) Result[T]

AndThen2 calls op if the result is Ok, otherwise returns the error of self. This function can be used for control flow based on Result values.

func (Result[T]) AsPtr

func (r Result[T]) AsPtr() *T

AsPtr returns its pointer or nil.

func (*Result[T]) Catch

func (r *Result[T]) Catch(withStackTrace ...bool)

Catch catches any panic and converts it to a Result error. It catches:

  • errutil.ErrBox (gust's own error type, value type)
  • error (regular Go errors, wrapped in ErrBox)
  • any other type (wrapped in ErrBox)

When a panic is caught, Catch can optionally capture the panic stack trace using PanicStackTrace() and wrap it with the error for better debugging. By default, stack trace is captured (withStackTrace defaults to true). Set withStackTrace to false to disable stack trace capture for better performance.

Example:

```go
func example() (result Result[string]) {
   defer result.Catch()  // With stack trace (default)
   Err[int]("int error").Unwrap()
   return Ok[string]("ok")
}

func exampleNoStack() (result Result[string]) {
   defer result.Catch(false)  // Without stack trace
   Err[int]("int error").Unwrap()
   return Ok[string]("ok")
}
```

func (Result[T]) ContainsErr

func (r Result[T]) ContainsErr(err any) bool

ContainsErr returns true if the result is an error containing the given value.

func (Result[T]) Err

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

Err returns error.

func (Result[T]) ErrVal

func (r Result[T]) ErrVal() any

ErrVal returns error inner value.

func (Result[T]) Expect

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

Expect returns the contained Ok value. Panics if the value is an error, with a panic message including the passed message, and the content of the error.

func (Result[T]) ExpectErr

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

ExpectErr returns the contained error. Panics if the value is not an error, with a panic message including the passed message, and the content of the [`Ok`].

func (Result[T]) Flatten

func (r Result[T]) Flatten(err error) Result[T]

Flatten converts from `(Result[T], error)` to Result[T].

Examples

import "github.com/andeya/gust/result"
var r1 = result.Ok(1)
var err1 = nil
var result1 = r1.Flatten(err1)
assert.Equal(t, result.Ok[int](1), result1)

var r2 = result.Ok(1)
var err2 = errors.New("error")
var result2 = r2.Flatten(err2)
assert.Equal(t, "error", result2.Err().Error())

var r3 = result.TryErr[int](errors.New("error"))
var err3 = nil
var result3 = r3.Flatten(err3)
assert.Equal(t, "error", result3.Err().Error())

func (Result[T]) Inspect

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

Inspect calls the provided closure with a reference to the contained value (if no error).

func (Result[T]) InspectErr

func (r Result[T]) InspectErr(f func(error)) Result[T]

InspectErr calls the provided closure with a reference to the contained error (if error).

func (Result[T]) IsErr

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

IsErr returns true if the result is error. NOTE: This is determined by whether t.IsSome() is false, not by e.IsEmpty(). This ensures that Err(nil) is correctly identified as an error state, following declarative programming principles where Err() explicitly declares an error result.

func (Result[T]) IsErrAnd

func (r Result[T]) IsErrAnd(f func(error) bool) bool

IsErrAnd returns true if the result is error and the value inside it matches a predicate.

func (Result[T]) IsOk

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

IsOk returns true if the result is Ok. NOTE: This is determined by whether t.IsSome() is true, not by e.IsEmpty(). This ensures that Err(nil) is correctly identified as an error state, following declarative programming principles where Err() explicitly declares an error result.

func (Result[T]) IsOkAnd

func (r Result[T]) IsOkAnd(f func(T) bool) bool

IsOkAnd returns true if the result is Ok and the value inside it matches a predicate.

func (*Result[T]) IsValid

func (r *Result[T]) IsValid() bool

IsValid returns true if the object is initialized.

func (Result[T]) Map

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

Map maps a Result[T] to Result[T] by applying a function to a contained Ok value, leaving an error untouched. This function can be used to compose the results of two functions.

func (Result[T]) MapErr

func (r Result[T]) MapErr(op func(error) (newErr any)) Result[T]

MapErr maps a Result[T] to Result[T] by applying a function to a contained error, leaving an Ok value untouched. This function can be used to pass through a successful result while handling an error.

func (Result[T]) MapOr

func (r Result[T]) MapOr(defaultOk T, f func(T) T) T

MapOr returns the provided default (if error), or applies a function to the contained value (if no error), Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use MapOrElse, which is lazily evaluated.

func (Result[T]) MapOrElse

func (r Result[T]) MapOrElse(defaultFn func(error) T, f func(T) T) T

MapOrElse maps a Result[T] to T by applying fallback function default to a contained error, or function f to a contained Ok value. This function can be used to unpack a successful result while handling an error.

func (Result[T]) MarshalJSON

func (r Result[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Result[T]) Next

func (r *Result[T]) Next() Option[T]

Next returns the next element of the iterator.

func (*Result[T]) NextBack

func (r *Result[T]) NextBack() Option[T]

NextBack returns the next element from the back of the iterator.

func (Result[T]) Ok

func (r Result[T]) Ok() Option[T]

Ok converts from `Result[T]` to `Option[T]`.

func (Result[T]) Or

func (r Result[T]) Or(r2 Result[T]) Result[T]

Or returns `r2` if `r` is `Err`, otherwise returns `r`. Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use OrElse, which is lazily evaluated.

func (Result[T]) Or2

func (r Result[T]) Or2(v2 T, err2 error) Result[T]

Or2 returns `Ret(v2, err2)` if `r` is `Err`, otherwise returns `r`.

func (Result[T]) OrElse

func (r Result[T]) OrElse(op func(error) Result[T]) Result[T]

OrElse calls op if the result is Err, otherwise returns the Ok value of self. This function can be used for control flow based on result values.

func (Result[T]) OrElse2

func (r Result[T]) OrElse2(op func(error) (T, error)) Result[T]

OrElse2 calls op if the result is Err, otherwise returns the Ok value of self. This function can be used for control flow based on result values.

func (Result[T]) Ref

func (r Result[T]) Ref() *Result[T]

Ref returns the pointer of the object.

func (*Result[T]) Remaining

func (r *Result[T]) Remaining() uint

Remaining returns the number of remaining elements in the iterator.

func (*Result[T]) SizeHint

func (r *Result[T]) SizeHint() (uint, Option[uint])

SizeHint returns a hint about the remaining size of the iterator.

func (Result[T]) Split

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

Split returns the tuple (T, error).

func (Result[T]) String

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

String returns the string representation.

func (Result[T]) ToX

func (r Result[T]) ToX() Result[any]

ToX converts from `Result[T]` to Result[any].

func (*Result[T]) UnmarshalJSON

func (r *Result[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Result[T]) Unwrap

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

Unwrap returns the contained Ok value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the error case explicitly, or call UnwrapOr or UnwrapOrElse. NOTE: This panics with error interface (from r.e.ToError()) to allow Result.Catch() to properly handle it.

func (Result[T]) UnwrapErr

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

UnwrapErr returns the contained error. Panics if the value is not an error, with a custom panic message provided by the [`Ok`]'s value.

func (Result[T]) UnwrapOr

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

UnwrapOr returns the contained Ok value or a provided default. Arguments passed to UnwrapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use UnwrapOrElse, which is lazily evaluated.

func (Result[T]) UnwrapOrDefault

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

UnwrapOrDefault returns the contained T or a non-nil-pointer zero T.

func (Result[T]) UnwrapOrElse

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

UnwrapOrElse returns the contained Ok value or computes it from a closure.

func (Result[T]) UnwrapUnchecked

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

UnwrapUnchecked returns the contained T.

func (Result[T]) XAnd

func (r Result[T]) XAnd(res Result[any]) Result[any]

XAnd returns res if the result is Ok, otherwise returns the error of self.

func (Result[T]) XAnd2

func (r Result[T]) XAnd2(v2 any, err2 error) Result[any]

XAnd2 returns `r` if `r` is `Err`, otherwise returns `Ret(v2, err2)`.

func (Result[T]) XAndThen

func (r Result[T]) XAndThen(op func(T) Result[any]) Result[any]

XAndThen calls op if the result is Ok, otherwise returns the error of self. This function can be used for control flow based on Result values.

func (Result[T]) XAndThen2

func (r Result[T]) XAndThen2(op func(T) (any, error)) Result[any]

XAndThen2 calls op if the result is Ok, otherwise returns the error of self. This function can be used for control flow based on Result values.

func (Result[T]) XMap

func (r Result[T]) XMap(f func(T) any) Result[any]

XMap maps a Result[T] to Result[any] by applying a function to a contained Ok value, leaving an error untouched. This function can be used to compose the results of two functions.

func (Result[T]) XMapOr

func (r Result[T]) XMapOr(defaultOk any, f func(T) any) any

XMapOr returns the provided default (if error), or applies a function to the contained value (if no error), Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use MapOrElse, which is lazily evaluated.

func (Result[T]) XMapOrElse

func (r Result[T]) XMapOrElse(defaultFn func(error) any, f func(T) any) any

XMapOrElse maps a Result[T] to `any` by applying fallback function default to a contained error, or function f to a contained Ok value. This function can be used to unpack a successful result while handling an error.

func (Result[T]) XOk

func (r Result[T]) XOk() Option[any]

XOk converts from `Result[T]` to `Option[any]`.

type VoidResult

type VoidResult = Result[void.Void]

VoidResult is an alias for Result[Void], representing a result that only indicates success or failure. This is equivalent to Rust's Result<(), E> and provides a simpler API than Result[Void].

Example:

```go
import "github.com/andeya/gust/result"
var res result.VoidResult = result.RetVoid(err)
if res.IsErr() {
	fmt.Println(res.Err())
}
```

func FmtErrVoid added in v1.20.6

func FmtErrVoid(format string, a ...any) VoidResult

FmtErrVoid wraps a failure result with a formatted error as VoidResult.

func OkVoid

func OkVoid() VoidResult

OkVoid returns Ok[Void](nil).

Example:

```go
import "github.com/andeya/gust/result"
var res result.VoidResult = result.OkVoid()
```

func RetVoid

func RetVoid(maybeError any) VoidResult

RetVoid wraps an error as VoidResult (Result[Void]). Returns Ok[Void](nil) if maybeError is nil, otherwise returns Err[Void](maybeError).

Example:

```go
import "github.com/andeya/gust/result"
var res result.VoidResult = result.RetVoid(maybeError)
```

func TryErrVoid

func TryErrVoid(err any) VoidResult

TryErrVoid wraps a failure result as VoidResult. NOTE: If err is nil, TryErrVoid(nil) returns OkVoid().

Jump to

Keyboard shortcuts

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