Browse Source

checking if one can mess with the order of .map_err() and .and_then()

master
Julio Biason 4 months ago
parent
commit
fec556587a
  1. 7
      andthenchaintest/Cargo.lock
  2. 6
      andthenchaintest/Cargo.toml
  3. 10
      andthenchaintest/src/main.rs

7
andthenchaintest/Cargo.lock generated

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "andthenchaintest"
version = "0.1.0"

6
andthenchaintest/Cargo.toml

@ -0,0 +1,6 @@
[package]
name = "andthenchaintest"
version = "0.1.0"
edition = "2021"
[dependencies]

10
andthenchaintest/src/main.rs

@ -0,0 +1,10 @@
fn main() {
let value: Result<u32, u32> = Err(20)
.map_err(|_: u32| 30)
.and_then(|_old: u32| Err(40));
// Note: Order does not affect these results; even if `.map_err()` comes before `.and_then()`,
// when `.and_then()` returns an error, it is captured by `.map_err()` again.
println!("{:?}", value);
}
Loading…
Cancel
Save