我收到了这条Ruust方法错误消息:
error[E0277]: the `?` operator can only be used on `Option`s,
not `Result`s, in an async function that returns `Option`
我必须承认,我经常遇到令我困惑的Rust错误消息,而对大多数其他程序员来说,它们是绝对有意义的.
所以,我提前为张贴这个问题道歉.
首先:错误消息中的第二个逗号是什么意思?我应该这样解读它吗?
如果[在另一个函数内]的异步函数调用返回类型Result
的枚举,则?
运算符只能应用if,且仅当相应的[其它]函数也返回Result
类型的枚举而不是Option
类型的枚举时
请原谅我的长篇大论.我希望我把我的观点讲明白了.
同样让我感到困惑的是具有相同引用的错误消息,即error[E0277],它列在official rust error codes index个国家中:
"您试图在需要某些特性的地方使用不实现某些特性的类型."
除了相同的标号外,这两个错误消息在哪个领域有任何共同之处?
下面是Rust生成的整个错误块:
error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in an async function that returns `Option`
--> src/utils/tokenizer.rs:72:73
|
70 | pub async fn clear(&self) -> Option<String> {
| _________________________________________________-
71 | | let mut conn = self.pool.get().await.unwrap();
72 | | let mut iter: redis::AsyncIter<i32> = conn.sscan("my_set").await?;
| | ^ use `.ok()?` if you want to discard the `Result<Infallible, Red
Error>` error information
73 | | while let Some(element) = iter.next_item().await {
... |
79 | | Some(String::from("A"))
80 | | }
| |_____- this function returns an `Option`
|
= help: the trait `FromResidual<Result<Infallible, RedisError>>` is not implemented for `std::option::Option<std::string::String>`
= help: the following other types implement trait `FromResidual<R>`:
<std::option::Option<T> as FromResidual<Yeet<()>>>
<std::option::Option<T> as FromResidual>
For more information about this error, try `rustc --explain E0277`.
典型的错误消息是什么?来自错误代码索引页的错误消息还是编译器生成的错误消息?