| Age | Commit message (Collapse) | Author | Lines |
|
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.
|
|
|
|
Fixes: #65492
|
|
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!
|
|
|
|
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.
|
|
|
|
The tracking issue https://github.com/rust-lang/rust/issues/50264
still has unresolved question for the corresponding `Result` methods.
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
discussion https://github.com/rust-lang/rust/issues/50264
|
|
Add Option::expect_none(msg) and unwrap_none()
These are `Option` analogues to `Result::expect_err` and `unwrap_err`.
|
|
r=QuietMisdreavus
Fix Pin urls in Option documentation
Fixes the following situation:

r? @QuietMisdreavus
|
|
r=scottmcm
Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*`
r? @RalfJung
|
|
|
|
|
|
These are `Option` analogues to `Result::expect_err` and `unwrap_err`.
|
|
|
|
Implement Option::contains and Result::contains
This increases consistency with other common data structures.
|
|
This increases consistency with other common data structures.
|
|
Add missing links in Option documentation
r? @rust-lang/docs
|
|
|
|
|
|
|
|
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!
|
|
|
|
|
|
Stabilize Option::xor
FCP done in https://github.com/rust-lang/rust/issues/50512#issuecomment-469527554 .
Closes #50512 .
|
|
|
|
|
|
squashed commit
|
|
|
|
|
|
|
|
Co-Authored-By: pnkfelix <pnkfelix@pnkfx.org>
|
|
termination.
|
|
Stabilize Option::copied
closes https://github.com/rust-lang/rust/issues/57126
|
|
closes https://github.com/rust-lang/rust/issues/57126
|
|
|
|
Option
|
|
Use more impl header lifetime elision
Inspired by seeing explicit lifetimes on these two:
- https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator
- https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not
And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore.
Most of the changes in here fall into two big categories:
- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)
I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm).
I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
|
|
There are two big categories of changes in here
- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)
I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
|
|
|
|
|
|
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.
|