#closures #traits #value #style #contained

map-self

Map a value itself instead of its contained value in usual closure style

1 unstable release

0.1.0 Dec 21, 2023

#2013 in Rust patterns

24 downloads per month
Used in 2 crates

MIT/Apache

7KB

crates.io

A Rust library crate that offers the MapSelf trait, implemented on all types.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Example:

let (hour, meridiem) = if use_12_hour_clock {
    self.hour_meridiem() // Yields 12-hour clock time.
        .map_self(|(hour, meridiem)| (hour, Some(meridiem)))
} else {
    (self.hour, None)
};

Example:

// Initialize time to check for double-click.
let mut last_click_time = Instant::now()
    .map_self_or_keep(|now| now.checked_sub(Duration::from_secs(60)));

No runtime deps