rust-osdev / volatile

Apache License 2.0
71 stars 19 forks source link

Volatile::map and Volatile::map_mut use slightly different `F` bounds? #14

Closed DianaNites closed 3 years ago

DianaNites commented 3 years ago

I was browsing the documentation and noticed that map takes F: FnOnce(&'a T) -> &'a U and T: 'a, but map_mut takes F: FnOnce(&mut T) -> &mut U and T: 'a and wondered about the difference?

phil-opp commented 3 years ago

The map_mut method is for &mut references (e.g. Volatile<&mut u32>) and gives full access to the wrapped value. The map method, in constrast, only requires a shared & reference (e.g. Volatile<&u32>), but does not allow modification of the wrapped value.

(I'm not sure if I understood your question right, so please let me know if anything is still unclear.)