4 ms·
Angle brackets aren't that uncommon, are they? Swift is a modern, elegant language that uses angle brackets for generics. Fortunately it uses the period instead
by jb1991 4y ago
Angle brackets aren't that uncommon, are they? Swift is a modern, elegant language that uses angle brackets for generics. Fortunately it uses the period instead of the double colon (thank goodness for that!) but I don't see anything ugly about brackets.
- ssokolow 4y agoIt's directly responsible for Rust needing the "turbofish" syntax to pin down generic return types as in let foo.iter().map(|x| x*2).collect::<Vec<_>>() If they'd used something like [T] for generics, then there'd be no collision with the < and > operators needing disambiguation in some contexts. They even have a Book of Mozilla-esque entry in their test suite named "Bastion of the Turbofish" to pin down an example of the problem case, complete with https://github.com/rust-lang/rust/blob/43192ca3d72ed0ca42ba913137585219ba0a691f/src/test/ui/parser/bastion-of-the-turbofish.rs https://github.com/rust-lang/rust/blob/43192ca3d72ed0ca42ba9...
- mvolfik 4y agoI don't think that's true - .collect[Vec[u8]]() - here you might be accessing property collect and taking the value at index denoted by the item of Vec at position denoted by the variable u8. And at the end calling the resulting thing? (That's not actually valid in rust afaik, you'd have to wrap it in parentheses like this `(...collect[])()`)
- Measter 4y agoThat is actually valid Rust, and it works exactly as you said: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dd960239ede4419f4beeaadd35cec434 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- ssokolow 4y agoThe argument that generics should have used [] generally goes hand in hand with the argument that [] for panicking indexing is a wart on Rust's "pit of success" design philosophy and that panicking indexing should have been more verbose to type than the .get() for Result-returning indexing... but probably less verbose to type than the `unsafe`, potentially UB-inducing `.get_unchecked()`.