diff rust/hg-core/src/dirstate_tree/owning.rs @ 48084:3d0a9c6e614d

dirstate: Remove the Rust abstraction DirstateMapMethods This Rust trait used to exist in order to allow the DirstateMap class exposed to Python to be backed by either of two implementations: one similar to the Python implementation based on a "flat" `HashMap<HgPathBuf, DirstateEntry>`, and the newer one based on a tree of nodes matching the directory structure of tracked files. A boxed trait object was used with dynamic dispatch. With the flat implementation removed and only the tree one remaining, this abstraction is not useful anymore and the concrete type can be stored directly. It remains that the trait was implemented separately for `DirstateMap<'_>` (which takes a lifetime parameter) and `OwningDirstateMap` (whose job is to wrap the former and hide the lifetime parameter), with the latter impl only forwarding calls. This changeset also removes this forwarding. Instead, the methods formerly of the `DirstateMapMethods` trait are now inherent methods implemented for `OwningDirstateMap` (where they will actually be used) but in the module that defines `DirstateMap`. This unusual setup gives access to the private fields of `DirstateMap` from those methods. Differential Revision: https://phab.mercurial-scm.org/D11517
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 27 Sep 2021 13:52:49 +0200
parents 37a41267d000
children d1210d56008b
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/owning.rs	Mon Sep 27 12:09:15 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/owning.rs	Mon Sep 27 13:52:49 2021 +0200
@@ -44,7 +44,7 @@
         Self { on_disk, ptr }
     }
 
-    pub fn get_mut_pair<'a>(
+    pub fn get_pair_mut<'a>(
         &'a mut self,
     ) -> (&'a [u8], &'a mut DirstateMap<'a>) {
         // SAFETY: We cast the type-erased pointer back to the same type it had
@@ -60,11 +60,11 @@
         (&self.on_disk, unsafe { &mut *ptr })
     }
 
-    pub fn get_mut<'a>(&'a mut self) -> &'a mut DirstateMap<'a> {
-        self.get_mut_pair().1
+    pub fn get_map_mut<'a>(&'a mut self) -> &'a mut DirstateMap<'a> {
+        self.get_pair_mut().1
     }
 
-    pub fn get<'a>(&'a self) -> &'a DirstateMap<'a> {
+    pub fn get_map<'a>(&'a self) -> &'a DirstateMap<'a> {
         // SAFETY: same reasoning as in `get_mut` above.
         let ptr: *mut DirstateMap<'a> = self.ptr.cast();
         unsafe { &*ptr }