mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-17 11:12:28 +08:00
doc: update doc for xerror package
This commit is contained in:
@@ -22,20 +22,20 @@ import (
|
|||||||
|
|
||||||
## Index
|
## Index
|
||||||
|
|
||||||
- [Unwrap](#Unwrap)
|
- [TryUnwrap](#TryUnwrap)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="Unwrap">Unwrap</span>
|
### <span id="TryUnwrap">TryUnwrap</span>
|
||||||
|
|
||||||
<p>Unwrap if err is nil then it returns a valid value. If err is not nil, Unwrap panics with err.</p>
|
<p>TryUnwrap if err is nil then it returns a valid value. If err is not nil, Unwrap panics with err.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Unwrap[T any](val T, err error) T
|
func TryUnwrap[T any](val T, err error) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:</b>
|
||||||
@@ -49,7 +49,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := xerror.Unwrap(strconv.Atoi("42"))
|
result1 := xerror.TryUnwrap(strconv.Atoi("42"))
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
|
|
||||||
_, err := strconv.Atoi("4o2")
|
_, err := strconv.Atoi("4o2")
|
||||||
@@ -59,7 +59,7 @@ func main() {
|
|||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
xerror.Unwrap(strconv.Atoi("4o2"))
|
xerror.TryUnwrap(strconv.Atoi("4o2"))
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 42
|
// 42
|
||||||
|
|||||||
@@ -22,20 +22,20 @@ import (
|
|||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
|
|
||||||
- [Unwrap](#Unwrap)
|
- [TryUnwrap](#TryUnwrap)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="Unwrap">Unwrap</span>
|
### <span id="TryUnwrap">TryUnwrap</span>
|
||||||
|
|
||||||
<p>检查error, 如果err为nil则展开,则它返回一个有效值,如果err不是nil则Unwrap使用err发生panic。</p>
|
<p>检查error, 如果err为nil则展开,则它返回一个有效值,如果err不是nil则TryUnwrap使用err发生panic。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Unwrap[T any](val T, err error) T
|
func TryUnwrap[T any](val T, err error) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:</b>
|
||||||
@@ -49,7 +49,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := xerror.Unwrap(strconv.Atoi("42"))
|
result1 := xerror.TryUnwrap(strconv.Atoi("42"))
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
|
|
||||||
_, err := strconv.Atoi("4o2")
|
_, err := strconv.Atoi("4o2")
|
||||||
@@ -59,7 +59,7 @@ func main() {
|
|||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
xerror.Unwrap(strconv.Atoi("4o2"))
|
xerror.TryUnwrap(strconv.Atoi("4o2"))
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 42
|
// 42
|
||||||
|
|||||||
Reference in New Issue
Block a user