rust: implement vcsgraph::RankedGraph for Index
authorpacien <pacien.trangirard@pacien.net>
Mon, 21 Feb 2022 18:06:02 +0100
changeset 48853 4346be456875
parent 48852 e633e660158f
child 48854 8b8054b8e5a7
rust: implement vcsgraph::RankedGraph for Index Differential Revision: https://phab.mercurial-scm.org/D12210
rust/hg-cpython/src/cindex.rs
--- a/rust/hg-cpython/src/cindex.rs	Mon Feb 21 18:05:54 2022 +0100
+++ b/rust/hg-cpython/src/cindex.rs	Mon Feb 21 18:06:02 2022 +0100
@@ -177,6 +177,20 @@
     }
 }
 
+impl vcsgraph::graph::RankedGraph for Index {
+    fn rank(
+        &self,
+        rev: Revision,
+    ) -> Result<vcsgraph::graph::Rank, vcsgraph::graph::GraphReadError> {
+        match unsafe {
+            (self.capi.fast_rank)(self.index.as_ptr(), rev as ssize_t)
+        } {
+            -1 => Err(vcsgraph::graph::GraphReadError::InconsistentGraphData),
+            rank => Ok(rank as usize),
+        }
+    }
+}
+
 impl RevlogIndex for Index {
     /// Note C return type is Py_ssize_t (hence signed), but we shall
     /// force it to unsigned, because it's a length