about summary refs log tree commit diff
path: root/src/libcore/option.rs
AgeCommit message (Collapse)AuthorLines
2020-04-11Document unsafety in `core::option`LeSeulArtichaut-2/+6
2020-03-19make "other" in docs of `Option::{zip,zip_with}` monofontWaffle-2/+2
2020-03-18fixes to `Option::{zip,zip_with}`Waffle-11/+9
- remove `#[inline]` attributes (see https://github.com/rust-lang/rust/pull/69997#discussion_r393942617) - fill tracking issue in `#[unstable]` attributes - slightly improve the docs
2020-03-18add `Option::{zip,zip_with}` methods under "option_zip" gateWaffle-0/+59
This commit introduces 2 methods - `Option::zip` and `Option::zip_with` with respective signatures: - zip: `(Option<T>, Option<U>) -> Option<(T, U)>` - zip_with: `(Option<T>, Option<U>, (T, U) -> R) -> Option<R>` Both are under the feature gate "option_zip". I'm not sure about the name "zip", maybe we can find a better name for this. (I would prefer `union` for example, but this is a keyword :( ) -------------------------------------------------------------------------------- Recently in a russian rust begginers telegram chat a newbie asked (translated): > Are there any methods for these conversions: > > 1. `(Option<A>, Option<B>) -> Option<(A, B)>` > 2. `Vec<Option<T>> -> Option<Vec<T>>` > > ? While second (2.) is clearly `vec.into_iter().collect::<Option<Vec<_>>()`, the first one isn't that clear. I couldn't find anything similar in the `core` and I've come to this solution: ```rust let tuple: (Option<A>, Option<B>) = ...; let res: Option<(A, B)> = tuple.0.and_then(|a| tuple.1.map(|b| (a, b))); ``` However this solution isn't "nice" (same for just `match`/`if let`), so I thought that this functionality should be in `core`.
2020-02-09Rollup merge of #68918 - brson:unwrapdoc, r=Dylan-DPCDylan DPC-10/+16
Don't use the word "unwrap" to describe "unwrap" methods It's tautological, and "unwrap" is essentially Rust-specific jargon. I was teaching a newbie some Rust, and doing the usual hand-waving about error handling using unwrap. They asked what 'unwrap' means. I said look it up in the docs. The docs read (paraphrased) "unwrap unwraps". I was embarrassed. This changes all the Option/Result functions with unwrapping behavior to use a variation on a single description: > "Returns the contained `Some/Ok` value [or ...]." It also renames the closure of `Result::unwrap_or_else` to `default` for consistency with `Option`, and perhaps makes a few other small tweaks. Previous: https://github.com/rust-lang/rust/pull/68849
2020-02-07Don't use the word 'unwrap' to describe core unwrapping functionsBrian Anderson-10/+16
It's tautological, and Rust-specific Jargon. This changes various Option/Result methods to consistently describe unwrapping behavior using the words "return", "contain", "consume". It also renames the closure argument of `Return::unwrap_or_else` to `default` to be consistent with `Option`.
2020-02-06Mark fn map_or() as eagerly evaluated.Tom A. Wagner-0/+6
In the docs for option.rs and result.rs, it is noted for all *_or() functions that they are eagerly evaluated, except for the map_or() function. This commit adds this missing documentation to the two files.
2020-02-01Update option.rsMarincia Catalin-2/+2
I updated the example of the `expect` examples so they won't contain depressing sentences any more !
2020-01-23use `diagnostic_item` and modify wordingEsteban Küber-0/+1
2020-01-09Rollup merge of #67966 - popzxc:core-std-matches, r=CentrilMazdak Farrokhzad-4/+1
Use matches macro in libcore and libstd This PR replaces matches like ```rust match var { value => true, _ => false, } ``` with use of `matches!` macro. r? @Centril
2020-01-08Use matches macro in libcore and libstdIgor Aleksanov-4/+1
2020-01-04Option's panics are all #[track_caller].Adam Perry-0/+6
Also includes a simple test with a custom panic hook to ensure we don't regress.
2019-11-26Format libcore with rustfmtDavid Tolnay-29/+53
This commit applies rustfmt with default settings to files in src/libcore *that are not involved in any currently open PR* to minimize merge conflicts. The list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in `outstanding_files`, the relevant commands were: $ find src/libcore -name '*.rs' | xargs rustfmt --edition=2018 $ rg libcore outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libcore.
2019-11-06Have tidy ensure that we document all `unsafe` blocks in libcoreOliver Scherer-0/+2
2019-10-28Rollup merge of #64747 - ethanboxx:master, r=CentrilMazdak Farrokhzad-3/+1
Stabilize `Option::flatten` - PR: https://github.com/rust-lang/rust/pull/60256 - Tracking issue: https://github.com/rust-lang/rust/issues/60258 @elahn > I was trying to `flat_map()` and found `map().flatten()` does the trick. This has been on nightly for 4 months, can we stabilise it? @ethanboxx > @Centril Helped me get this merged. What is the stabilization process? @Centril > @ethanboxx I'd just file a PR to stabilize it and we'll ask T-libs to FCP. So here I am. I am was unsure what number to put in `since = "-"` so I copied what someone had done in a recent PR.
2019-10-22Apply clippy::single_match suggestionMateusz Mikuła-3/+2
2019-10-20Rename the default argument 'def' to 'default'David Sinclair-2/+2
Fixes: #65492
2019-10-19Remove unneeded `ref` from docsCarol (Nichols || Goulding)-2/+2
Will reduce confusion like in https://users.rust-lang.org/t/help-understanding-the-ref-t-syntax/33779 since match ergonomics means you (almost) never have to say `ref` anymore!
2019-10-19Stabilize `Option::flatten`Ethan Brierley-3/+1
2019-10-05Rollup merge of #64708 - SimonSapin:option-deref, r=CentrilTyler Mandry-6/+2
Stabilize `Option::as_deref` and `Option::as_deref_mut` The tracking issue https://github.com/rust-lang/rust/issues/50264 still has unresolved question for the corresponding `Result` methods.
2019-09-30Fixed a misleading documentation issue #64844hman523-1/+1
2019-09-23Stabilize Option::deref and Option::deref_mutSimon Sapin-6/+2
The tracking issue https://github.com/rust-lang/rust/issues/50264 still has unresolved question for the corresponding `Result` methods.
2019-09-17Elide lifetimes in `Pin<&(mut) Self>`Taiki Endo-2/+2
2019-08-30Add missing examples for Option typeGuillaume Gomez-0/+31
2019-08-06Rollup merge of #62459 - timvermeulen:result_sum_internal_iteration, r=scottmcmMazdak Farrokhzad-2/+5
Use internal iteration in the Sum and Product impls of Result and Option This PR adds internal iteration to the `ResultShunt` iterator type underlying the `Sum` and `Product` impls of `Result`. I had to change `ResultShunt` to hold a mutable reference to an error instead, similar to `itertools::ProcessResults`, in order to be able to pass the `ResultShunt` itself by value (which is necessary for internal iteration). `ResultShunt::process` can unfortunately no longer be an associated function because that would make it generic over the lifetime of the error reference, which wouldn't work, so I turned it into the free function `process_results`. I removed the `OptionShunt` type and forwarded the `Sum` and `Product` impls of `Option` to their respective impls of `Result` instead, to avoid having to repeat the internal iteration logic.
2019-07-29Add links to None in Option docLzu Tao-2/+2
2019-07-29Use internal iteration in the Sum and Product impls of Result and OptionTim Vermeulen-2/+5
2019-07-27Refactoring use commun code between option, result and accumStargateur-40/+2
2019-07-18Use DerefMutYuki Okushi-1/+1
2019-07-18renamed `inner_deref` feature's `deref*()` methods `as_deref*()` as per ↵Brad Gibson-2/+13
discussion https://github.com/rust-lang/rust/issues/50264
2019-07-17Auto merge of #62596 - cuviper:expect_none, r=rkruppebors-1/+94
Add Option::expect_none(msg) and unwrap_none() These are `Option` analogues to `Result::expect_err` and `unwrap_err`.
2019-07-15Rollup merge of #62491 - GuillaumeGomez:fix-pin-urls-for-option, ↵Mark Rousskov-0/+4
r=QuietMisdreavus Fix Pin urls in Option documentation Fixes the following situation: ![Screenshot from 2019-07-08 13-24-59](https://user-images.githubusercontent.com/3050060/60806822-55dfdc00-a184-11e9-9ee3-279e82fc92bd.png) r? @QuietMisdreavus
2019-07-12Rollup merge of #62431 - czipperz:add-messages-to-must-use-is_-methods, ↵Mazdak Farrokhzad-2/+3
r=scottmcm Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*` r? @RalfJung
2019-07-12Add tracking issue 62633Josh Stone-2/+2
2019-07-11Make cold unwraps take &dyn DebugJosh Stone-3/+3
2019-07-11Add Option::expect_none(msg) and unwrap_none()Josh Stone-1/+94
These are `Option` analogues to `Result::expect_err` and `unwrap_err`.
2019-07-08Fix Pin urls in Option documentationGuillaume Gomez-0/+4
2019-07-08Rollup merge of #62356 - soc:topic/contains, r=CentrilMazdak Farrokhzad-0/+26
Implement Option::contains and Result::contains This increases consistency with other common data structures.
2019-07-07Implement Option::contains, Result::contains and Result::contains_errSimon Ochsenreither-0/+26
This increases consistency with other common data structures.
2019-07-07Rollup merge of #62379 - GuillaumeGomez:option-doc-links, r=QuietMisdreavusMazdak Farrokhzad-10/+22
Add missing links in Option documentation r? @rust-lang/docs
2019-07-05Wrap lineChris Gregory-1/+2
2019-07-05Add messages to Option and Result must_use for is_*Chris Gregory-2/+2
2019-07-04Add missing links in Option documentationGuillaume Gomez-10/+22
2019-07-04Rollup merge of #62344 - matklad:simplify-option, r=sfacklerMazdak Farrokhzad-9/+1
simplify Option::get_or_insert I am pretty sure that the optimized result will be the same, and it's one `unsafe` less in the stdlib!
2019-07-03simplify Option::get_or_insertAleksey Kladov-9/+1
2019-07-01Use mem::take instead of mem::replace with defaultChris Gregory-1/+1
2019-06-13Rollup merge of #60376 - lzutao:stabilize-option_xor, r=SimonSapinMazdak Farrokhzad-3/+1
Stabilize Option::xor FCP done in https://github.com/rust-lang/rust/issues/50512#issuecomment-469527554 . Closes #50512 .
2019-06-05Stabilize Option::xorLzu Tao-3/+1
2019-06-01Implement Clone::clone_from for Option.Mara Bos-1/+20
2019-04-26Add flatten option for `Option<Option<T>>`Ethan Brierley-1/+31
squashed commit