|
1 | | -# type |
| 1 | +# types |
2 | 2 |
|
3 | | -Bring the Rust [Result Option] type to Golang |
| 3 | +Bring the Rust [Result Option] types to Golang |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
7 | | - `go get github.com/initdc/type` |
| 7 | + `go get github.com/initdc/types` |
8 | 8 |
|
9 | 9 | ## Usage |
10 | 10 |
|
11 | 11 | ```go |
| 12 | +package e2e_test |
| 13 | + |
12 | 14 | import ( |
13 | | - . "github.com/initdc/type/option" |
14 | | - . "github.com/initdc/type/result" |
| 15 | + "fmt" |
| 16 | + . "github.com/initdc/types/option" |
| 17 | + types "github.com/initdc/types/result" |
| 18 | + "testing" |
15 | 19 | ) |
16 | 20 |
|
17 | | -// Option |
18 | | -s := Some(1) |
| 21 | +func TestE2E(t *testing.T) { |
| 22 | + // Option |
| 23 | + s1 := Some(1) |
| 24 | + |
| 25 | + var s2 Option[int] |
| 26 | + s2.None() |
| 27 | + |
| 28 | + n1 := None[int]() |
19 | 29 |
|
20 | | -var s Option[int] |
21 | | -s.None() |
22 | 30 |
|
23 | | -n := None[int]() |
| 31 | + // Result |
| 32 | + var r1 types.Result[int, string] |
| 33 | + r1.Ok(1) |
24 | 34 |
|
25 | | -// Result |
26 | | -var r Result[int, string] |
27 | | -r.Ok(1) |
| 35 | + var e1 types.Result[int, string] |
| 36 | + e1.Err("error") |
28 | 37 |
|
29 | | -var e Result[int, string] |
30 | | -e.Err("error") |
| 38 | + r2 := types.Ok[int, string](1) |
| 39 | + e2 := types.Err[int, string]("error") |
31 | 40 |
|
| 41 | + fmt.Printf("%#v\n", s1) |
| 42 | + fmt.Printf("%#v\n", s2) |
| 43 | + fmt.Printf("%#v\n", n1) |
32 | 44 |
|
33 | | -r := Ok[int, string](1) |
34 | | -e := Err[int, string]("error") |
| 45 | + fmt.Printf("%#v\n", r1) |
| 46 | + fmt.Printf("%#v\n", e1) |
| 47 | + fmt.Printf("%#v\n", r2) |
| 48 | + fmt.Printf("%#v\n", e2) |
| 49 | +} |
35 | 50 | ``` |
36 | 51 |
|
37 | 52 | ## Contributing |
38 | 53 |
|
39 | | -Bug reports and pull requests are welcome on GitHub at https://github.com/initdc/type. |
| 54 | +Bug reports and pull requests are welcome on GitHub at https://github.com/initdc/types. |
0 commit comments