4 ms·
Great to see Rustup reach 1.0 release. I like how easy it makes to test out different versions of rust and its toolchains. I like the '..' addition for structs
by anuragsoni 10y ago
Great to see Rustup reach 1.0 release. I like how easy it makes to test out different versions of rust and its toolchains.
I like the '..' addition for structs. It definitely improved the pattern matching over structs.
let p = Point { x: 0, y: 1, z: 2 };
match p {
Point { x, .. } => println!("x is {}", x),
}
Congrats to the Rust Team for another good release!!
- petters 10y agoQuestion from someone who don't know Rust: Why two dots instead of an ellipsis (three)?
- kryptiskt 10y agoThree dots doesn't look like an ellipsis in a monospaced font, it's far too wide.
- echelon 10y agoIt can if you use a monospaced font with ligatures. Take a look at Fira Code [1]. I use it in Vim and IntelliJ, and it looks great with Rust and other functional languages. [1] https://github.com/tonsky/FiraCode https://github.com/tonsky/FiraCode
- petters 10y agoWell, I'm sure you know what I meant.
- swsieber 10y agoI'm pretty sure he did know what you meant, and offered a serious response. I think he's suggesting that perhaps the aesthetics of the ellipsis is what prevented it from being selected.
- deleted 10y ago[deleted]
- belovedeagle 10y agoIt's already a keyword or operator (not sure which) used in range notation (1..2); why add a new operator when an old one will do?
- iopq 10y agoThree dots are for inclusive ranges, two for exclusive
- cannam 10y agoThere must be some interesting reason why ".." and not the more common "..." - I wonder what?
- the_duke 10y agoThey probably 'copied' Haskell here, which also uses "..".
- pdexter 10y agoHaskell doesn't have this feature though. I mean it does, but you can just leave out the ones you don't want matched, you don't have to put in any dots.
- echelon 10y agoIt's less to type. The double period is already used for lots of other things in the language, so it feels like the correct choice.
- swsieber 10y agoReading through, they treat a range (like 1 .. 10 ) as pattern matching 1 2 3 4 5 6 7 8 9 10, with .. representing 2 3 4 5 6 7 8 9. In that light, it actually makes sense.
- cannam 10y agoAh of course, that is quite widely used (e.g. Perl). If you already have that, I can see why you'd reuse the same token. (edit: ok, I see from other replies that it's not that simple)
- anuragsoni 10y agoMinor correction, to match a range the syntax would be 1 ... 10
- tatterdemalion 10y agoNo particular reason. `..` and `...` both exist in the language, `..` is exclusive range and `...` is inclusive range. `..` is only in expressions right now, whereas `...` is only in patterns. Eventually, both will be available everywhere, possibly. At very least, `..` in patterns is getting added soon. Since this is a pattern thing, probably `..` was chosen when `...` was the only range available in patterns, to distinguish this from that range pattern more. However, `..` will now be available in patterns, so its just historical. (This is a longstanding feature, what's changed is just making it apply to more patterns.)
- echelon 10y agoThis is such a win for pattern matching! I tried using this exact syntax last month and I was sad to see it didn't exist. It feels so natural to see it now. Rust is such an awesome language. Every design decision feels so right. Go, Rust, go!