about summary refs log tree commit diff
path: root/src/libstd/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-04-11 17:52:11 +0200
committerGitHub <noreply@github.com>2020-04-11 17:52:11 +0200
commit03a724bd486da1d2691df3d8709c688a0704f1e0 (patch)
tree5938040505931f21859fcd4226d284e9b0a6bcd0 /src/libstd/sys/unix/stack_overflow.rs
parent5ecc18f3ece1124a56ff76a74c3eb4153be5b3b8 (diff)
parentdb0c39fba5d596e286238c21b11b9aa9e1701b5b (diff)
downloadrust-03a724bd486da1d2691df3d8709c688a0704f1e0.tar.gz
rust-03a724bd486da1d2691df3d8709c688a0704f1e0.zip
Rollup merge of #70996 - ChaiTRex:master, r=Amanieu
Add or_insert_with_key to Entry of HashMap/BTreeMap

Going along with `or_insert_with`, `or_insert_with_key` provides the `Entry`'s key to the lambda, avoiding the need to either clone the key or the need to reimplement this body of this method from scratch each time.

This is useful when the initial value for a map entry is derived from the key. For example, the introductory Rust book has an example Cacher struct that takes an expensive-to-compute lambda and then can, given an argument to the lambda, produce either the cached result or execute the lambda.

---

I'm fairly new to Rust, so any optimizations, corrections to types, better names, better documentation, or whatever else would be appreciated. I'd like to thank Arnavion on freenode for helping me to implement a very similar method when I found that `or_insert_with_key` was unavailable.

As a somewhat-related note, this implements https://github.com/rust-lang/rfcs/issues/1202 from 2015, so if this pull request is accepted, that should be closed.
Diffstat (limited to 'src/libstd/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions