about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs
diff options
context:
space:
mode:
authorWaffle <waffle.lapkin@gmail.com>2020-03-13 11:51:55 +0300
committerWaffle <waffle.lapkin@gmail.com>2020-03-18 10:25:58 +0300
commita5206f9749faf60f6b4163a526de9ad18241503e (patch)
tree02efc5c900847a5b482fe140c92c87547013c65d /src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs
parentd939f708d960161d23b964309ba68ff207fc0ead (diff)
downloadrust-a5206f9749faf60f6b4163a526de9ad18241503e.tar.gz
rust-a5206f9749faf60f6b4163a526de9ad18241503e.zip
add `Option::{zip,zip_with}` methods under "option_zip" gate
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`.
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs')
0 files changed, 0 insertions, 0 deletions