作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
loop {
match stream.write(&buffer) {
Ok(_) => break,
_ => {}
}
}
有没有办法以更具可读性/惯用的方式编写它?我不需要在
match
内做任何事情, 在
Ok
之后我不需要任何操作或在
Err
之后,因为每当返回
Ok
时,缓冲区都会更新为引用.
while match some_fn() != Ok() {
...
}
最佳答案
一般情况由 ForceBru's answer 涵盖,但因为你有一个 Result
并且不关心 Ok
里面的值,您可以使用 Result::is_ok
(或 Result::is_err
):
while stream.write(&buffer).is_err() {}
正如
rodrigo in the comments 所指出的:
Worth noting that Rust 1.42 adds the
matches!
macro, so you can writewhile matches!(stream.write(&buffer), Ok(_)) {}
, useful for other enums that lack theis_*
functions.
关于loops - 当我只关心一个变体而不关心变体中的值时,循环匹配的惯用方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64451464/
我一直在学习如何创建自定义 ArrayAdapter 并熟悉重写 ArrayAdapter 的 getViewTypeCount 和 getItemViewType 方法。 为什么 Android V
我是一名优秀的程序员,十分优秀!