Re:Mistakes with Rust smart pointers: when Deref goes wrong
by saghm on Monday July 10, 2023 @08:27PM
(#36674986)
Am I correct in thinking this is the type of thing change that fits the criteria to be implemented in a new edition? Assuming the issue is the same one I often run into (i.e. 'a versus for<'a>), it seems like special casing this for closures passed as arguments would be quite nice, but the fact that it wasn't done for 2018 or 2021 makes me think that maybe it's not something that would qualify for introducing in this way.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by tialaramex on Tuesday July 11, 2023 @04:06AM
(#36677859)
It's not "just" syntax, so it couldn't "just" be a new edition, but I suppose it's conceivable that a hack could be invented and then the old behaviour grandfathered into prior editions as was done for impl IntoIterator for [T; N] in 2021 Edition.
That's a heavy lift though, you may need to carry this special code around in every compiler, forever, and I haven't even figured out what such code should look like, it might be really hard to even write it.
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by saghm on Tuesday July 11, 2023 @12:31PM
(#36683395)
Good to know! I appreciate the insight
Re:Mistakes with Rust smart pointers: when Deref goes wrong
by 3836293648 on Tuesday July 11, 2023 @12:41PM
(#36683541)
How would removing the lambda affect back compat?
Interestingly you can ask whether a string is ASCII, "this".is_ascii() is a predicate which does exactly that, but for what I think is your question, "are they all ASCII caps?" you'd need to go via an iterator and a lambda: "THIS".bytes().all(|b| b.is_ascii_uppercase())
The iterator is because there is no provision of each such predicate over the whole string, which seems reasonable (the character class predicates are provided on u8 (ASCII only), and on char (all of them)), but the lambda is due to Rust's 1.0 compatibility commitment plus an unfortunate historical choice. If not for compatibility we'd fix it so you could just write "THIS".bytes().all(u8::is_ascii_uppercase)