Documentation
¶
Overview ¶
Package must implements assertions.
Index ¶
- func CatchFunc[X any](f func() X) func() (x X, err error)
- func Check(err error) error
- func Equal[T comparable](a T, b T)
- func False(q bool)
- func Func[X any](f func() (X, error)) func() X
- func Never(args ...interface{})
- func Ok[T any](t T, ok bool) T
- func Result[T any](t T, err error) T
- func True(q bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CatchFunc ¶
CatchFunc takes a function f() => x that may panic, and instead returns a function f() => (x, error).
func Check ¶
Check panics if the error is not nil. Otherwise, it returns a nil error (so that it is convenient to chain).
func Equal ¶ added in v2.3.3
func Equal[T comparable](a T, b T)
Equal panics unless the provided comparable values are equal.
func Func ¶
Func takes a function f() => (x, error), and returns a function f() => x that may panic in the event of error.
func Never ¶ added in v2.0.13
func Never(args ...interface{})
Never signifies code that should never be reached. It raises a panic when called.
The args parameter defines an optional fmt.Sprintf-style format string and arguments.
func Ok ¶
Ok accepts a (value, ok) tuple as input and panics if ok is false, otherwise returns value.
func Result ¶
Result accepts a (value, err) tuple as input and panics if err != nil, otherwise returns value. The error raised by panic is wrapped in another error.
For example, must.Result(os.Open("doesnotexist")) may panic with an error like "unexpected error in must.Result[*os.File]: open doesnotexist: no such file or directory". On success, returns *os.File.
Types ¶
This section is empty.