rust/hg-core/src/dirstate_tree/owning.rs
changeset 48069 3d0a9c6e614d
parent 48041 37a41267d000
child 48567 d1210d56008b
equal deleted inserted replaced
48068:bf8837e3d7ce 48069:3d0a9c6e614d
    42         let ptr: *mut () = ptr.cast();
    42         let ptr: *mut () = ptr.cast();
    43 
    43 
    44         Self { on_disk, ptr }
    44         Self { on_disk, ptr }
    45     }
    45     }
    46 
    46 
    47     pub fn get_mut_pair<'a>(
    47     pub fn get_pair_mut<'a>(
    48         &'a mut self,
    48         &'a mut self,
    49     ) -> (&'a [u8], &'a mut DirstateMap<'a>) {
    49     ) -> (&'a [u8], &'a mut DirstateMap<'a>) {
    50         // SAFETY: We cast the type-erased pointer back to the same type it had
    50         // SAFETY: We cast the type-erased pointer back to the same type it had
    51         // in `new`, except with a different lifetime parameter. This time we
    51         // in `new`, except with a different lifetime parameter. This time we
    52         // connect the lifetime to that of `self`. This cast is valid because
    52         // connect the lifetime to that of `self`. This cast is valid because
    58         // new   `&mut` to that of `self`. This is valid because the
    58         // new   `&mut` to that of `self`. This is valid because the
    59         // raw pointer is   to a boxed value, and `self` owns that box.
    59         // raw pointer is   to a boxed value, and `self` owns that box.
    60         (&self.on_disk, unsafe { &mut *ptr })
    60         (&self.on_disk, unsafe { &mut *ptr })
    61     }
    61     }
    62 
    62 
    63     pub fn get_mut<'a>(&'a mut self) -> &'a mut DirstateMap<'a> {
    63     pub fn get_map_mut<'a>(&'a mut self) -> &'a mut DirstateMap<'a> {
    64         self.get_mut_pair().1
    64         self.get_pair_mut().1
    65     }
    65     }
    66 
    66 
    67     pub fn get<'a>(&'a self) -> &'a DirstateMap<'a> {
    67     pub fn get_map<'a>(&'a self) -> &'a DirstateMap<'a> {
    68         // SAFETY: same reasoning as in `get_mut` above.
    68         // SAFETY: same reasoning as in `get_mut` above.
    69         let ptr: *mut DirstateMap<'a> = self.ptr.cast();
    69         let ptr: *mut DirstateMap<'a> = self.ptr.cast();
    70         unsafe { &*ptr }
    70         unsafe { &*ptr }
    71     }
    71     }
    72 
    72