about summary refs log tree commit diff
path: root/src/libcore/option.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-1740/+0
2020-07-17Rollup merge of #73930 - a1phyr:feature_const_option, r=dtolnayManish Goregaokar-4/+8
Make some Option methods const Tracking issue: #67441 Constantify the following methods of `Option`: - `as_ref` - `is_some` - `is_none` - `iter` (not sure about this one, but it is possible, and will be useful when const traits are a thing) cc @rust-lang/wg-const-eval @rust-lang/libs
2020-07-14Remove string comparison and use diagnostic item insteadEsteban Küber-0/+1
2020-07-01Add feature const_optionBenoît du Garreau-4/+8
2020-06-25Remove irrelevant commentGary Guo-5/+0
2020-06-13Stabilize Option::zipLzu Tao-3/+5
2020-05-13Update src/libcore/option.rsFaris Sufyan-0/+2
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-13Update src/libcore/option.rsFaris Sufyan-0/+1
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-13Update src/libcore/option.rsFaris Sufyan-1/+1
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-13Update src/libcore/option.rsFaris Sufyan-0/+1
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-13Update src/libcore/option.rsFaris Sufyan-0/+1
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-13Update src/libcore/option.rsFaris Sufyan-1/+1
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-13Update src/libcore/option.rsFaris Sufyan-0/+1
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-13Update src/libcore/option.rsFaris Sufyan-1/+1
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2020-05-10Fix link to `map` documentation in exampleFaris Sufyan-1/+1
Co-authored-by: Timo <timorcb@gmail.com>
2020-05-05Fix exampleDolpheyn-1/+1
2020-05-05Fix comment positionDolpheyn-1/+1
2020-05-05Document From trait for Option implementationsDolpheyn-0/+39
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