Skip to content

Implement .pop_opt() and .shift_opt() for vec#7602

Closed
bluss wants to merge 2 commits intorust-lang:masterfrom
bluss:vec-pop-opt
Closed

Implement .pop_opt() and .shift_opt() for vec#7602
bluss wants to merge 2 commits intorust-lang:masterfrom
bluss:vec-pop-opt

Conversation

@bluss
Copy link
Contributor

@bluss bluss commented Jul 5, 2013

Implement methods .pop_opt() -> Option<T> and .shift_opt() -> Option<T> to allow retrieval of front/back of a vec in one operation without fail. .pop() and .shift() are changed to reuse the former two methods.

Follows the naming of the previous method .head_opt()

@bluss
Copy link
Contributor Author

bluss commented Jul 5, 2013

.head() (and .last()) says fail!("head: empty vector"), and I thought it was clearer style than the informal message in .pop()

blake2-ppc added 2 commits July 5, 2013 20:32
Add a function to safely retrieve the last element of a ~[T], as
Option<T>. Implement pop() using pop_opt(); it benches the same as the
old implementation when tested with optimization level 2.
Add a function to safely retrieve the first element of a ~[T], as
Option<T>. Implement shift() using shift_opt().

Add tests for both .shift() and .shift_opt()
@bluss
Copy link
Contributor Author

bluss commented Jul 5, 2013

Pushed again to fix the doc comments for push and push_opt. It should be "removes last element" for pop.

Edit: I meant pop and not push here. Brain farts... too many of em

@bblum
Copy link
Contributor

bblum commented Jul 5, 2013

I still think "sorry, cannot pop and empty vector" should stay.

@bluss
Copy link
Contributor Author

bluss commented Jul 6, 2013

should I push again? Or can bblum take back the r+?

@thestinger
Copy link
Contributor

@blake2-ppc: you could just remove the commit and push

@bluss
Copy link
Contributor Author

bluss commented Jul 6, 2013

done. Unfortunately the discussion is gone with that. It was decided to not have "sorry" in any error messages.

@bluss
Copy link
Contributor Author

bluss commented Jul 6, 2013

bors added a commit that referenced this pull request Jul 7, 2013
Implement methods `.pop_opt() -> Option<T>` and `.shift_opt() -> Option<T>` to allow retrieval of front/back of a vec in one operation without fail. .pop() and .shift() are changed to reuse the former two methods.

Follows the naming of the previous method .head_opt()
@bors bors closed this Jul 7, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 3, 2021
…dnet

Set applicability of needless_collect to MaybeIncorrect

Fixes rust-lang#88333

changelog: Set applicability of [`needless_collect`] to MaybeIncorrect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants