Skip to content
Snippets Groups Projects
Commit 15011324a80b authored by Georges Racinet's avatar Georges Racinet :squid:
Browse files

rust: made the crate of hg-cpython importable

The crate name is actually `rusthg`. This has the side effect
of running the doctest of the `py_shared_iterator` macro which
was really inconsistent, and after basic fixes, exposed that the
macro itself was poorly scoped.
parent a642c0a3860f
No related branches found
No related tags found
2 merge requests!1292Draft: 7.0rc preparation,!1134Bootstraping PyO3 Rust bindings
......@@ -6,7 +6,7 @@
[lib]
name='rusthg'
crate-type = ["cdylib"]
crate-type = ["cdylib", "rlib"]
[dependencies]
cpython = { version = "0.7.2", features = ["extension-module"] }
......
......@@ -11,7 +11,6 @@
use cpython::{
PyBytes, PyClone, PyDict, PyObject, PyResult, Python, UnsafePyLeaked,
};
use std::cell::RefCell;
use crate::dirstate::dirstate_map::v2_error;
use crate::dirstate::dirstate_map::DirstateMap;
......
......@@ -8,8 +8,6 @@
//! Bindings for the `hg::dirstate::dirs_multiset` file provided by the
//! `hg-core` package.
use std::cell::RefCell;
use cpython::{
exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult,
Python, UnsafePyLeaked,
......
......@@ -8,7 +8,7 @@
//! Bindings for the `hg::dirstate::dirstate_map` file provided by the
//! `hg-core` package.
use std::cell::{RefCell, RefMut};
use std::cell::RefMut;
use cpython::{
exc, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, PyNone, PyObject,
......
......@@ -43,4 +43,8 @@
/// Do not copy it out of the function call.
///
/// # Example
/// ```
/// use cpython::*;
/// use std::collections::hash_map::{HashMap, Iter as HashMapIter};
/// use rusthg::py_shared_iterator;
///
......@@ -46,7 +50,6 @@
///
/// ```
/// struct MyStruct {
/// inner: HashMap<Vec<u8>, Vec<u8>>;
/// pub struct MyStruct {
/// inner: HashMap<Vec<u8>, Vec<u8>>
/// }
///
/// py_class!(pub class MyType |py| {
......@@ -50,9 +53,9 @@
/// }
///
/// py_class!(pub class MyType |py| {
/// @shared data inner: MyStruct;
/// @shared data inner_shared: MyStruct;
///
/// def __iter__(&self) -> PyResult<MyTypeItemsIterator> {
/// let leaked_ref = self.inner_shared(py).leak_immutable();
/// MyTypeItemsIterator::from_inner(
/// py,
......@@ -54,9 +57,9 @@
///
/// def __iter__(&self) -> PyResult<MyTypeItemsIterator> {
/// let leaked_ref = self.inner_shared(py).leak_immutable();
/// MyTypeItemsIterator::from_inner(
/// py,
/// unsafe { leaked_ref.map(py, |o| o.iter()) },
/// unsafe { leaked_ref.map(py, |o| o.inner.iter()) },
/// )
/// }
/// });
......@@ -76,8 +79,8 @@
///
/// py_shared_iterator!(
/// MyTypeItemsIterator,
/// UnsafePyLeaked<HashMap<'static, Vec<u8>, Vec<u8>>>,
/// UnsafePyLeaked<HashMapIter<'static, Vec<u8>, Vec<u8>>>,
/// MyType::translate_key_value,
/// Option<(PyBytes, PyBytes)>
/// );
/// ```
......@@ -80,7 +83,8 @@
/// MyType::translate_key_value,
/// Option<(PyBytes, PyBytes)>
/// );
/// ```
#[macro_export]
macro_rules! py_shared_iterator {
(
$name: ident,
......@@ -89,5 +93,5 @@
$success_type: ty
) => {
py_class!(pub class $name |py| {
data inner: RefCell<$leaked>;
data inner: std::cell::RefCell<$leaked>;
......@@ -93,5 +97,5 @@
def __next__(&self) -> PyResult<$success_type> {
def __next__(&self) -> cpython::PyResult<$success_type> {
let mut leaked = self.inner(py).borrow_mut();
let mut iter = unsafe { leaked.try_borrow_mut(py)? };
match iter.next() {
......@@ -101,7 +105,7 @@
}
}
def __iter__(&self) -> PyResult<Self> {
def __iter__(&self) -> cpython::PyResult<Self> {
Ok(self.clone_ref(py))
}
});
......@@ -110,6 +114,6 @@
pub fn from_inner(
py: Python,
leaked: $leaked,
) -> PyResult<Self> {
) -> cpython::PyResult<Self> {
Self::create_instance(
py,
......@@ -114,6 +118,6 @@
Self::create_instance(
py,
RefCell::new(leaked),
std::cell::RefCell::new(leaked),
)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment