-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
pushed
for returning a mutable reference to the pushed element.
#1821
Comments
Hi @ticki, Why not |
I'd really like this too, but bikeshed: I don't like the name |
@KalitaAlexey Two reasons:
|
@comex what about |
@ticki Sure. |
The emplacement implementation could be made to return the reference to an element that has been just emplaced. I wonder, though, which is more useful – returning the index of the element or the reference to the element itself. |
Returning a reference allows working around the implicit boundcheck, and honestly, getting the index isn't that hard (it's free too). |
push_ref
for returning a mutable reference to the pushed element.pushed
for returning a mutable reference to the pushed element.
IIRC, |
Making match something() {
0 => println!("zero"),
value => vec.push(value),
} |
You can use |
It is annoying to manually fetch the last element, which is unsurprisingly quite common after a push. The most obvious thing would be to make
Vec::<T>::push()
return a&mut T
, but this is strictly speaking a breaking change. It would be cool to get some crater data on whether this in practice is an issue (i.e. if people don't put the;
afterpush()
in functions returning()
).The more realistic change is to add a method,
push_ref
, returning&mut T
.The text was updated successfully, but these errors were encountered: