mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
20 lines
359 B
Rust
20 lines
359 B
Rust
#[inline(always)]
|
|
fn map<T, U, F>(slf: Option<T>, f: F) -> Option<U>
|
|
where
|
|
F: FnOnce(T) -> U,
|
|
{
|
|
match slf {
|
|
Some(x) => Some(f(x)),
|
|
None => None,
|
|
}
|
|
}
|
|
|
|
// EMIT_MIR simple_option_map_e2e.ezmap.PreCodegen.after.mir
|
|
pub fn ezmap(x: Option<i32>) -> Option<i32> {
|
|
map(x, |n| n + 1)
|
|
}
|
|
|
|
fn main() {
|
|
assert_eq!(None, ezmap(None));
|
|
}
|