rust-osdev / volatile

Apache License 2.0
70 stars 19 forks source link

consider removing the lifetime from `VolatilePtr` #40

Closed kadiwa4 closed 1 year ago

kadiwa4 commented 1 year ago

VolatilePtr is used for memory-mapped I/O where lifetimes are not useful. Also, as a volatile counterpart to *-pointers, it would make sense if it didn't have a lifetime either.

It seems it was added in c3d6b9a8a1692d71a90e2947b11c4c0d24a729b0 to make map_mut sound, but that function has been removed again and today's map function can easily be used to map from a 'static to another 'static VolatilePtr. Does it still serve a purpose?

Freax13 commented 1 year ago

Personally I also use VolatilePtr in cases where the lifetime is not 'static e.g. the lifetime depends on the lifetime of the mapped memory.

kadiwa4 commented 1 year ago

@Freax13 and VolatileRef doesn't work for that case? I will close the issue then

Freax13 commented 1 year ago

Accesses to a VolatileRef happen through a VolatilePtr returned by VolatileRef::as_ptr, VolatileRef::as_mut_ptr or VolatileRef::into_ptr. All of these functions return a VolatilePtr with a lifetime which is not static if the lifetime of VolatileRef isn't also static. In other words removing, the lifetime from VolatilePtr would also break VolatileRef.

kadiwa4 commented 1 year ago

makes sense