Interactions
@h4kor Being a beginner I also do not know, but this the kind of question for which an LLM can hallucinate if not a correct answer, than at least a helpful one.
I'd try Claude.
(Original Post)
@h4kor That’s the correct way to do it. You could make it a little shorter using the convenience macro « matches! » (std::matches) which does the work of the match statement for you in the background.
(Original Post)
@h4kor not sure if this would be idiomatic but I would probably go with something like:
.filter(|r| if let RoomKind::BedRoom(_) = r.kind { true } else { false })
https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html
(Original Post)
@h4kor https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html recommends `if let` for avoiding awkward matches, but not sure how much "better" it is in this case:
```
.filter(|r| if let RoomKind::BedRoom(_) = r.kind { true } else { false })
```
(Original Post)
@h4kor looks like you're looking for the matches! macro.
https://docs.rs/matches/latest/matches/macro.matches.html
(Original Post)
@h4kor How about matches! ?
.filter(|r| matches!(r.kind, RoomKind::BedRoom(_)))
https://doc.rust-lang.org/std/macro.matches.html
(Original Post)
@h4kor https://doc.rust-lang.org/book/ch06-00-enums.html ?
(Original Post)
@h4kor using the matches! macro?
https://doc.rust-lang.org/stable/std/macro.matches.html
(Original Post)
@h4kor It looks good to me, but I'm following to see if there is another way.
(Original Post)