Open Ddystopia opened 3 months ago
Currently, for example map_mut has following signature:
map_mut
pub fn map_mut<F, U>(self, f: F) -> OwningRefMut<O, U> where U: ?Sized, O: StableAddress, F: FnOnce(&mut T) -> &mut U
which makes impossible view types like this (U + 'a also include &'a mut i32, so it is +- backwards compatible):
&'a mut i32
use owning_ref::OwningRefMut; struct View<'a> { a: &'a mut i32, b: &'a mut i32, } fn main() { let vec = vec![1, 2, 3, 4, 5]; let it = OwningRefMut::new(vec).map_mut(|v| { let (a, b) = v.split_at_mut(1); View { a: &mut a[0], b: &mut b[0] } }); }
Signature may become something like that:
pub fn map_mut<F, U>(self, f: F) -> OwningRefMut<O, U> where U, O: StableAddress, F: FnOnce(&mut T) -> U
I propose change api of methods in crate to allow such use cases.
I need this because I need a view type for later stages and creating view type every time is expensive, because it is hot
There is crate yoke and they are doing pretty much the same, but only for immutable references
yoke
https://docs.rs/yoke
Currently, for example
map_mut
has following signature:which makes impossible view types like this (U + 'a also include
&'a mut i32
, so it is +- backwards compatible):Signature may become something like that:
I propose change api of methods in crate to allow such use cases.
I need this because I need a view type for later stages and creating view type every time is expensive, because it is hot