39 ms·
What's the difference and advantage, other than less typing, of this over: match *Arc::new("hello").as_ref() { "hi" => {} "hello" => {}
by sfink 2y ago
What's the difference and advantage, other than less typing, of this over:
match *Arc::new("hello").as_ref() {
"hi" => {}
"hello" => {}
_ => {}
(Sorry, Rust newbie here)
- estebank 2y agoPatterns can be arbitrarily complex. If you have struct Foo { bar: Arc<String>, } Then it's the difference between today's if let Foo { bar } = val { if &*bar == "hi" { } } And the potential future if let Foo { bar: "hi" } = val {} The more complex the pattern, the bigger the conciseness win and levels of nesting you can remove. This comes up more often for me with `Box`, in the context of AST nodes, but because I use nightly I can use `box` patterns, which is the same feature but only for `Box` and that will never be stabilized.