3 ms·
> I don't understand this one at all. What's wrong with "as"? That it silently overflows. > And if you need a checked conversion just write a small wrapper fu
by masklinn 9y ago
> I don't understand this one at all. What's wrong with "as"?
That it silently overflows.
> And if you need a checked conversion just write a small wrapper function?
A better suggestion would be to wait for TryFrom/TryInto which IIRC should be stabilised soon-ish.
> So unless I'm missing something something like:
Assignment (https://doc.rust-lang.org/reference/expressions.html#assignment-expressions https://doc.rust-lang.org/reference/expressions.html#assignm...) not declaration (https://doc.rust-lang.org/reference/statements.html#declaration-statements https://doc.rust-lang.org/reference/statements.html#declarat...). So
(a, b) = (1, 2)
given pre-existing non-redeclared a and b. Of course this is not very useful for such a trivial example but a common case is some sort of procedural loop e.g.
let (mut a, mut b) = (0, 0);
for it in thing {
(a, b) = <something>
}
// use a and b here
currently you have to assign to (1+) temporary variables before porting that to the actual bindings you care about.
- simias 9y agoIt's true that a "checked_as" would come handy from time to time and seems to be in line with the "Rust spirit". But again, since the author seems to be arguing in favor of C it seems like an odd complaint. C even makes it tricky to check for integer overflow while Rust has the checked_ family of functions. In C if you get it wrong it's undefined behavior territory baby. Ditto with the tuple thing, C doesn't have tuples and won't let you destructure anything. I guess my overall point is that these complaints seems to pit Rust against some other high level languages like Common Lisp or Haskell but his conclusion is basically "C rulez, Rust droolz".
- dgfgfdagasdfgfa 9y agoAlso, detecting overflow while casting seems pretty trivial to implement as a macro itself if you aren't willing to wait for the language to pick up the need.
- andolanra 9y agoThere is an open issue (an old one!) about assignment to tuples, but it's not entirely a no-brainer as to how to implement it while keeping Rust's grammar LL(k): https://github.com/rust-lang/rfcs/issues/372 https://github.com/rust-lang/rfcs/issues/372