diff rust/hg-cpython/src/revlog.rs @ 43951:f98f0e3ddaa1

rust-index: add a function to convert PyObject index for hg-core Function in hg-core need something implementing the `Graph` trait. Right now, the `hg-cpython` entry points directly turn the PyObject passed as argument into a `cindex::Index`. However, if we start having the option to use an Index in Rust, we need to dispatch between the different possible PyObject we could receive. So move the "duplicate" call into a unified function. When time come. It will be easy to update the logic of all interface when the time come. Differential Revision: https://phab.mercurial-scm.org/D7653
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 13 Dec 2019 19:59:59 +0100
parents
children b69d5f3a41d0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rust/hg-cpython/src/revlog.rs	Fri Dec 13 19:59:59 2019 +0100
@@ -0,0 +1,17 @@
+// revlog.rs
+//
+// Copyright 2019 Georges Racinet <georges.racinet@octobus.net>
+//
+// This software may be used and distributed according to the terms of the
+// GNU General Public License version 2 or any later version.
+
+use crate::cindex;
+use cpython::{PyObject, PyResult, Python};
+
+/// Return a Struct implementing the Graph trait
+pub(crate) fn pyindex_to_graph(
+    py: Python,
+    index: PyObject,
+) -> PyResult<cindex::Index> {
+    cindex::Index::new(py, index)
+}