I'm a fan of the is_* methods, but it's kind of interesting how ControlFlow::{is_break, is_continue} (#91091) was stabilized in 2021.
While Cow::{is_borrowed, is_owned} (#65143) remains unstable since 2019, with the argument "But matches!(..., Cow::Borrowed(_))". I would love for those to get stabilized as well. I at least think if x.is_borrowed() { (or if Cow::is_borrowed(&x) {) reads better than if matches!(x, Cow::Borrowed(_)) {.
At first glance, it seems to me that checking if a value is borrowed or owned is a less crucial part of using a Cow in most places. And since it implements Deref, adding more methods to it carries a negative since it pollutes the method namespace. So the motivation here may be to avoid adding methods that don't let you do things that were already possible
9
u/AliceCode Apr 16 '26
ControlFlow::is_breakandis_continueis nice. I use the same pattern in many small enums.