mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-29 01:01:19 +08:00
Simplify code
This commit is contained in:
parent
df3838b924
commit
7e55c6f342
@ -90,10 +90,7 @@ inline fun LoginResult.requireSuccess(lazyMessage: (LoginResult) -> String) {
|
|||||||
* 检查 [this] 为 [LoginResult.SUCCESS].
|
* 检查 [this] 为 [LoginResult.SUCCESS].
|
||||||
* 失败则 [error]
|
* 失败则 [error]
|
||||||
*/
|
*/
|
||||||
fun LoginResult.requireSuccess() {
|
fun LoginResult.requireSuccess() = requireSuccess { "Login failed: $this" }
|
||||||
if (requireSuccessOrNull() === null)
|
|
||||||
error("Login failed: $this")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查 [this] 为 [LoginResult.SUCCESS].
|
* 检查 [this] 为 [LoginResult.SUCCESS].
|
||||||
@ -101,10 +98,7 @@ fun LoginResult.requireSuccess() {
|
|||||||
*
|
*
|
||||||
* @return 成功时 [Unit], 失败时 `null`
|
* @return 成功时 [Unit], 失败时 `null`
|
||||||
*/
|
*/
|
||||||
fun LoginResult.requireSuccessOrNull(): Unit? {
|
fun LoginResult.requireSuccessOrNull(): Unit? = if (this == SUCCESS) Unit else null
|
||||||
return if (this == SUCCESS) Unit else null
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查 [this] 为 [LoginResult.SUCCESS].
|
* 检查 [this] 为 [LoginResult.SUCCESS].
|
||||||
|
Loading…
Reference in New Issue
Block a user