pub struct FnMap(/* private fields */);
Expand description
Single thread only FnMap implementation.
This implementation is zero cost.
Implementations§
Source§impl FnMap
impl FnMap
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/example.rs (line 4)
3fn main() {
4 let map = FnMap::new();
5
6 fn one() -> i32 {
7 println!("one computed");
8 1
9 }
10
11 let a = *map.get(|| map.get(one) + 1);
12 dbg!(a);
13 assert_eq!(a, 2);
14
15 let b = *map.get(|| map.get(one) + 1);
16 dbg!(b);
17 assert_eq!(b, 2);
18
19 let c = *map.get(one);
20 dbg!(c);
21 assert_eq!(c, 1);
22}
pub fn get_ptr<T: 'static + Send>( &self, key_fn: impl FnOnce() -> T, ) -> NonNull<T>
Sourcepub fn get<T: 'static + Send>(&self, key: impl FnOnce() -> T) -> &T
pub fn get<T: 'static + Send>(&self, key: impl FnOnce() -> T) -> &T
Get or compute value using key
Examples found in repository?
examples/example.rs (line 11)
3fn main() {
4 let map = FnMap::new();
5
6 fn one() -> i32 {
7 println!("one computed");
8 1
9 }
10
11 let a = *map.get(|| map.get(one) + 1);
12 dbg!(a);
13 assert_eq!(a, 2);
14
15 let b = *map.get(|| map.get(one) + 1);
16 dbg!(b);
17 assert_eq!(b, 2);
18
19 let c = *map.get(one);
20 dbg!(c);
21 assert_eq!(c, 1);
22}
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for FnMap
impl !RefUnwindSafe for FnMap
impl !Sync for FnMap
impl Unpin for FnMap
impl !UnwindSafe for FnMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more