Once_type_map, a type map you can fill through &self and get &T (with a bit of unsafe)
The Rust Programming Language Forum
Once_type_map, a type map you can fill through &self and get &T (with a bit of unsafe)
I like the Extensions type map from http, and recently needed the same thing in my own code. Two things got in the way: I didn't want to depend on an HTTP crate just for a type map, and inserting into http::Extensions needs &mut self. That doesn't work when the object is shared, e.g. behind an Arc and used concurrently. So I wrote OnceTypeMap: think of it as a OnceLock per type. Values are set through &self (get_or_init, insert) and returned as plain &T tied to the borrow of the map, with no lo...
0 comments
No comments yet.