Julio Biason
2 years ago
4 changed files with 44 additions and 0 deletions
@ -0,0 +1,7 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
version = 3 |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "dontcollectresulttest" |
||||||
|
version = "0.1.0" |
@ -0,0 +1,8 @@ |
|||||||
|
[package] |
||||||
|
name = "dontcollectresulttest" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2021" |
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[dependencies] |
@ -0,0 +1,4 @@ |
|||||||
|
# DontCollectResultTest |
||||||
|
|
||||||
|
Checking if one can change the way `.collect()` collects stuff by changing the |
||||||
|
expected resulting type. |
@ -0,0 +1,25 @@ |
|||||||
|
fn is_even(val: u8) -> Result<u8, u8> { |
||||||
|
if val % 2 == 0 { |
||||||
|
Ok(val) |
||||||
|
} else { |
||||||
|
Err(val) |
||||||
|
} |
||||||
|
} |
||||||
|
fn main() { |
||||||
|
let values = [2u8, 2, 2, 2, 2, 1]; |
||||||
|
println!( |
||||||
|
"Result<Vec>: {:?}", |
||||||
|
values |
||||||
|
.iter() |
||||||
|
.map(|x| is_even(*x)) |
||||||
|
.collect::<Result<Vec<u8>, u8>>() |
||||||
|
); |
||||||
|
|
||||||
|
print!( |
||||||
|
"Vec<Result>: {:?}", |
||||||
|
values |
||||||
|
.iter() |
||||||
|
.map(|x| is_even(*x)) |
||||||
|
.collect::<Vec<Result<u8, u8>>>() |
||||||
|
); |
||||||
|
} |
Loading…
Reference in new issue