-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC: Casting From by as_cast #3413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Rust has, generally, been trying to move away from |
@CraftSpider |
First: Because we can soft-deprecate it instead, make less code use it going forwards, and even if we can't remove it, we can replace it with better alternatives. It already is useful in exactly one main scenario - dynamic unsizing - and we don't need to make it more confusing by adding more hard-to-teach behavior. And thinking of that, that's another issue - Second: This isn't about optimization, this is about behavior. We can't change behavior just because it's inconvenient, that's part of our version promises. Third: If we want to add another |
@CraftSpider // default
a as T where T == T_as_castable ~ a as T; // nothing changes
// new
a as T ~ T::from(a);
(a : U) as T<U> ~ T::from(a);
a as Result<T,_> ~ T::try_from(a);
(a : U) as Result<T<U>,_> ~ T::try_from(a); |
IMHO, As others have mentioned, dynamic unsizing is just one of the cases where While mathematical operations make sense to have syntax sugar since they're so much more easily readable that way (I much prefer
|
I've been meaning to write a RFC that supersedes |
@Aloso Wow! |
On the topic of deprecating |
@asquared31415 Thanks, I added your proposal to alternatives |
It has been said before, but I'll repeat it at this closing comment: Thanks everyone for the discussion. I will close this RFC now to reduce the load on the sync lang team meetings and leave it to async zulip discussions to determine the future of |
This RFC proposes new abilities for
as
(as_cast) castingFrom
Trait implementations.Like this:
Rendered
This proposal was inspired by "smart constructors" discussion in #3408 RFC.