0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rust で Optional の None チェック

Posted at

どう書くの

if Optional型.is_none() {
    return;
}

おまけ

どう書くかわからなくてこんな感じに書いてたら、

if let Some(_) = manager.get(msg.guild(&ctx.cache).await.unwrap().id) {

} else {
    return;
}

コンパイラが教えてくれた

warning: redundant pattern matching, consider using `is_some()`
  --> src/handler/mod.rs:25:16
   |
25 |         if let Some(_) = manager.get(msg.guild(&ctx.cache).await.unwrap().id) {
   |         -------^^^^^^^------------------------------------------------------- help: try this: `if manager.get(msg.guild(&ctx.cache).await.unwrap().id).is_some()`
   |
   = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

warning: 1 warning emitted
warning: this boolean expression can be simplified
  --> src/handler/mod.rs:25:12
   |
25 |         if !manager.get(msg.guild(&ctx.cache).await.unwrap().id).is_some() {
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `manager.get(msg.guild(&ctx.cache).await.unwrap().id).is_none()`
   |
   = note: `#[warn(clippy::nonminimal_bool)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?