3 ms·
It's a high level language with algebraic data types and fantastic type checking. I'll use it where ever I darn well please.
by eYrKEC2 2y ago
It's a high level language with algebraic data types and fantastic type checking. I'll use it where ever I darn well please.
- runeblaze 2y agoSometimes I write Rust with Arc and Rc sprinkled everywhere because I just need a dialect of OCaml.
- estebank 2y agoThe only thing that's really missing is deref patterns so that you can pattern match on an Arc<T> with a T pattern.
- goku12 2y agoShouldn't this be possible already? Deref is implemented for Arc<T>. [1] https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-Deref-for-Arc%3CT,+A%3E https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-Dere... [2] https://rust-lang.github.io/rfcs/2005-match-ergonomics.html https://rust-lang.github.io/rfcs/2005-match-ergonomics.html
- estebank 2y agoI mean having the following work: match Arc::new("hello") { "hi" => {} "hello" => {} _ => {} } It is an extension of match ergonomics, called deref patterns. There's some experimental code to make it work for `String` to `&str` (`if let "hi" = String::from("hi") {}`), but it is not anywhere close to finished. The final version will likely have something like a `trait DerefPure: Deref {}` signaling trait. There is disagreement on whether giving users the possibility to execute non-idempotent, non-cheap behavior on `Deref` and allow them to `impl DerefPure` for those types would be a big enough foot-gun to restrict this only to std or not.
- sfink 2y agoWhat'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.