Skip to content

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

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

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

Conversation

@bluss

@blussbluss commented Jul 5, 2013

Copy link
Copy Markdown
Contributor

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

bluss commented Jul 5, 2013

Copy link
Copy Markdown
ContributorAuthor

.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

bluss commented Jul 5, 2013

Copy link
Copy Markdown
ContributorAuthor

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

bblum commented Jul 5, 2013

Copy link
Copy Markdown
Contributor

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

@bluss

bluss commented Jul 6, 2013

Copy link
Copy Markdown
ContributorAuthor

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

@thestinger

Copy link
Copy Markdown
Contributor

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

@bluss

bluss commented Jul 6, 2013

Copy link
Copy Markdown
ContributorAuthor

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

@bluss

bluss commented Jul 6, 2013

Copy link
Copy Markdown
ContributorAuthor

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()
@borsbors 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
Fixesrust-lang#88333
changelog: Set applicability of [`needless_collect`] to MaybeIncorrect
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
7602: Check for dyn impls in method resolution r=flodiebold a=Veykril
Fixesrust-lang#6777
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Sign up for freeto 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

@bluss@bblum@thestinger@bors