rust-revlog: a trait for the revlog index
authorGeorges Racinet <georges.racinet@octobus.net>
Wed, 22 Jan 2020 16:35:56 +0100
changeset 44181 3fb39dc2e356
parent 44180 d84420232492
child 44182 9896a8d0d3d2
rust-revlog: a trait for the revlog index As explained in the doc comment, this is the minimum needed for our immediate concern, which is to implement a nodemap in Rust. The trait will be later implemented in `hg-cpython` by the index Python object implemented in C, thanks to exposition of the corresponding functions as a capsule. The `None` return cases in `node()` match what the `index_node()` C function does. Differential Revision: https://phab.mercurial-scm.org/D7789
rust/hg-core/src/revlog.rs
--- a/rust/hg-core/src/revlog.rs	Fri Jan 24 17:10:45 2020 -0800
+++ b/rust/hg-core/src/revlog.rs	Wed Jan 22 16:35:56 2020 +0100
@@ -40,3 +40,17 @@
     ParentOutOfRange(Revision),
     WorkingDirectoryUnsupported,
 }
+
+/// The Mercurial Revlog Index
+///
+/// This is currently limited to the minimal interface that is needed for
+/// the [`nodemap`](nodemap/index.html) module
+pub trait RevlogIndex {
+    /// Total number of Revisions referenced in this index
+    fn len(&self) -> usize;
+
+    /// Return a reference to the Node or `None` if rev is out of bounds
+    ///
+    /// `NULL_REVISION` is not considered to be out of bounds.
+    fn node(&self, rev: Revision) -> Option<&Node>;
+}