-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.go
36 lines (29 loc) · 822 Bytes
/
check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2024 Nikolay Pakulin (@pakuula). All rights reserved.
// Use of this source code is governed by LGPL-3.0 licence.
// The text of the licence can be found in the LICENSE.txt file.
package main
import (
"errors"
"fmt"
"github.com/pakuula/go-rusty/result"
)
func main() {
fmt.Println(MustReturn())
fmt.Println(MustError())
fmt.Println(MustPanic())
}
func MustError() (err error) {
defer result.CatchError(&err)
result.Err[int](errors.New("must be an error")).Must()
return
}
func MustReturn() (res result.Result[int]) {
defer result.Catch(&res)
val := result.Err[int](errors.New("must be an error")).Must()
return result.Val(val)
}
func MustPanic() (res result.Result[int]) {
defer result.Catch(&res)
val := result.Err[int](errors.New("must be an error")).Unwrap()
return result.Val(val)
}