summary refs log tree commit diff
path: root/src/libcore/option.rs
AgeCommit message (Collapse)AuthorLines
2019-01-13stabilize transpose_result in 1.33Mazdak Farrokhzad-3/+1
2018-12-26Auto merge of #56534 - xfix:copied, r=@SimonSapinbors-0/+42
Add unstable Iterator::copied() Initially suggested at https://github.com/bluss/rust-itertools/pull/289, however the maintainers of itertools suggested this may be better of in a standard library. The intent of `copied` is to avoid accidentally cloning iterator elements after doing a code refactoring which causes a structure to be no longer `Copy`. This is a relatively common pattern, as it can be seen by calling `rg --pcre2 '[.]map[(][|](?:(\w+)[|] [*]\1|&(\w+)[|] \2)[)]'` on Rust main repository. Additionally, many uses of `cloned` actually want to simply `Copy`, and changing something to be no longer copyable may introduce unnoticeable performance penalty. Also, this makes sense because the standard library includes `[T].copy_from_slice` to pair with `[T].clone_from_slice`. This also adds `Option::copied`, because it makes sense to pair it with `Iterator::copied`. I don't think this feature is particularly important, but it makes sense to update `Option` along with `Iterator` for consistency.
2018-12-26Add a tracking issue for Option::copiedKonrad Borowski-2/+2
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-23Rollup merge of #56939 - cramertj:pin-stabilization, r=alexcrichtonMazdak Farrokhzad-3/+3
Pin stabilization This implements the changes suggested in https://github.com/rust-lang/rust/issues/55766#issue-378417538 and stabilizes the `pin` feature. @alexcrichton also listed several "blockers" in that issue, but then in [this comment](https://github.com/rust-lang/rust/issues/55766#issuecomment-445074980) mentioned that they're more "TODO items": > In that vein I think it's fine for a stabilization PR to be posted at any time now with FCP lapsed for a week or so now. The final points about self/pin/pinned can be briefly discussed there (if even necessary, they could be left as the proposal above). Let's settle these last bits here and get this thing stabilized! :) r? @alexcrichton cc @withoutboats
2018-12-23Merge branch 'master' into copiedKonrad Borowski-1/+1
2018-12-23Improve docs for collecting into `Option`sPascal Hertleif-9/+31
Changes the original example to use more idiomatic formatting as well as `.checked_add`. Also adds a second example to show a case where the `.collect` returns `None`.
2018-12-21Stabilize PinTaylor Cramer-2/+2
2018-12-21Update Pin API to match the one proposed for stabilizationTaylor Cramer-1/+1
Remove pin::Unpin reexport and add Unpin to the prelude. Change Pin associated functions to methods. Rename get_mut_unchecked_ to get_unchecked_mut Remove impl Unpin for Pin Mark Pin repr(transparent)
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-1/+1
2018-12-05Add unstable Option::copied()Konrad Borowski-0/+42
2018-10-08Bump the `Option::replace` stabilize version to 1.31.0Clément Renault-1/+1
2018-10-08Stabilize the `Option::replace` methodClément Renault-3/+1
2018-09-29Use impl_header_lifetime_elision in libcoreScott McMurray-8/+8
2018-09-19Auto merge of #53877 - withoutboats:compositional-pin, r=aturonbors-4/+14
Update to a new pinning API. ~~Blocked on #53843 because of method resolution problems with new pin type.~~ @r? @cramertj cc @RalfJung @pythonesque anyone interested in #49150
2018-09-17Cleanup and fix method resolution issueTaylor Cramer-4/+2
2018-09-14Rollup merge of #53218 - weiznich:feature/option_ref_into, r=KodrAuskennytm-0/+14
Add a implementation of `From` for converting `&'a Option<T>` into `Option<&'a T>` I'm not sure if any annotations regarding the stabilization are needed or in general what's the correct process of adding such an impl. cc @sgrif (We have talked about this)
2018-09-06Fix invalid urlsGuillaume Gomez-7/+5
2018-09-01Update to a new pinning API.Without Boats-4/+16
2018-08-23move PinMut into pin module and export through stdNiv Kaminer-1/+1
2018-08-10Also add a `From` implementation for `&mut Option<T>` -> `Option<&mut T>'Georg Semmler-0/+7
2018-08-09Add stability attributeGeorg Semmler-0/+1
2018-08-09inline some short functionsM Farkas-Dyck-0/+4
2018-08-09Add a implementation of `From` for converting `&'a Option<T>` intoGeorg Semmler-0/+6
`Option<&'a T>`
2018-07-29resolved upstream merge conflictsBrad Gibson-5/+80
2018-07-18Rollup merge of #52218 - rivertam:patch-1, r=withoutboatskennytm-2/+4
Amend option.take examples It wasn't abundantly clear to me what `.take` returned. Perhaps this is a slightly frivolous change, but I think it's an improvement. =) Apologies if I'm not following proper procedures.
2018-07-10Amend option.take examplesBen Berman-2/+4
It wasn't abundantly clear to me what `.take` returned. Perhaps this is a slightly frivolous change, but I think it's an improvement. =) Apologies if I'm not following proper procedures.
2018-07-09Fix the documentation of `Option::replace`Clément RENAULT-1/+1
2018-07-04Implement `Option::replace` in the core libraryKerollmops-0/+27
2018-06-26Rollup merge of #51730 - MajorBreakfast:pin-get-mut-unchecked, r=withoutboatsPietro Albini-1/+1
New safe associated functions for PinMut - Add safe `get_mut` and `map` - Rename unsafe equivalents to `get_mut_unchecked` and `map_unchecked` The discussion about this starts [in this comment](https://github.com/rust-lang/rust/issues/49150#issuecomment-399604573) on the tracking issue.
2018-06-23`PinMut`: Add safe `get_mut` and rename unsafe fns to `get_mut_unchecked` ↵Josef Reinhard Brandl-1/+1
and `map_unchecked`
2018-06-20Replace unreachable! with unreachable_uncheckedMartin Glagla-3/+3
2018-05-22Add Option::as_pin_mutTaylor Cramer-0/+10
2018-05-15Add Option::xor methodClar Charr-0/+36
2018-04-30fixed some and added more testsBrad Gibson-1/+1
2018-04-26refactored to implement without traitBrad Gibson-18/+11
2018-04-26added DerefOption and DerefResult + tests to stdBrad Gibson-2/+19
2018-04-05Remove uses of option_filter featureThayne McCombs-2/+0
2018-04-01Stabilize `Option::filter`.Thayne McCombs-1/+1
Fixes #45860
2018-03-31Commit code for option size hintPhlosioneer-1/+6
2018-03-20Implement some trivial size_hints for various iteratorsPhlosioneer-0/+5
This also implements ExactSizeIterator where applicable. Addresses most of the Iterator traits mentioned in #23708.
2018-03-06Stabilize option_ref_mut_clonedMatt Brubeck-2/+1
Closes #43738.
2018-03-06Auto merge of #48768 - kennytm:rollup, r=kennytmbors-3/+3
Rollup of 14 pull requests - Successful merges: #48403, #48432, #48546, #48573, #48590, #48657, #48727, #48732, #48753, #48754, #48761, #48474, #48507, #47463 - Failed merges:
2018-03-03core: Update stability attributes for FusedIteratorUlrik Sverdrup-3/+3
2018-03-03core: Stabilize FusedIteratorUlrik Sverdrup-3/+3
FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate.
2018-02-26Fix doctest failurePhlosioneer-1/+0
Tried to be fancy with print statements.
2018-02-25Change the example string to something arbitraryPhlosioneer-4/+5
The choice of string is arbitrary, so all references to a number in the string were removed. The string is now the standard "Hello world!".
2018-02-24Slight modification to the as_ref example of std::option::OptionPhlosioneer-2/+2
A user in a reddit thread was confused by the name of the variable "num_as_int"; they thought the example was trying to convert the string "10" as if it were binary 2 by calling str::len(). In reality, the example is simply demonstrating how to take an immutable reference to the value of an Option. The confusion comes from the coincidence that the length of the string "10" is also its binary representation, and the implication from the variable names that a conversion was occuring ("num_as_str" to "num_as_int"). This PR changes the example number to 12 instead of 10, and changes the variable name from "num_as_int" to "num_length" to better communicate what the example is doing. The reddit thread: https://www.reddit.com/r/rust/comments/7zpvev/notyetawesome_rust_what_use_cases_would_you_like/dur39xw/
2018-01-20Rollup merge of #47193 - cramertj:result-opts, r=TimNNGuillaume Gomez-0/+29
Add transpose conversions for nested Option and Result These impls are useful when working with combinator methods that expect an option or a result, but you have a `Result<Option<T>, E>` instead of an `Option<Result<T, E>>` or vice versa.
2018-01-16Remove incorrect `Default::default` links, add a new oneGeoffry Song-7/+4
`map_or` and `map_or_else` don't use `Default::default`, but `unwrap_or_default` does.