##// END OF EJS Templates
rust-cpython: rustdoc improvements...
Georges Racinet -
r41220:dcf81826 default
parent child Browse files
Show More
@@ -5,8 +5,23 b''
5 // This software may be used and distributed according to the terms of the
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 //! Bindings for the hg::ancestors module provided by the
8 //! Bindings for the `hg::ancestors` module provided by the
9 //! `hg-core` crate. From Python, this will be seen as `rustext.ancestor`
9 //! `hg-core` crate. From Python, this will be seen as `rustext.ancestor`
10 //! and can be used as replacement for the the pure `ancestor` Python module.
11 //!
12 //! # Classes visible from Python:
13 //! - [`LazyAncestors`] is the Rust implementation of
14 //! `mercurial.ancestor.lazyancestors`.
15 //! The only difference is that it is instantiated with a C `parsers.index`
16 //! instance instead of a parents function.
17 //!
18 //! - [`AncestorsIterator`] is the Rust counterpart of the
19 //! `ancestor._lazyancestorsiter` Python generator.
20 //! From Python, instances of this should be mainly obtained by calling
21 //! `iter()` on a [`LazyAncestors`] instance.
22 //!
23 //! [`LazyAncestors`]: struct.LazyAncestors.html
24 //! [`AncestorsIterator`]: struct.AncestorsIterator.html
10 use cindex::Index;
25 use cindex::Index;
11 use cpython::{
26 use cpython::{
12 ObjectProtocol, PyClone, PyDict, PyModule, PyObject, PyResult, Python,
27 ObjectProtocol, PyClone, PyDict, PyModule, PyObject, PyResult, Python,
@@ -19,16 +34,16 b' use std::cell::RefCell;'
19
34
20 /// Utility function to convert a Python iterable into a Vec<Revision>
35 /// Utility function to convert a Python iterable into a Vec<Revision>
21 ///
36 ///
22 /// We need this to feed to AncestorIterators constructors because
37 /// We need this to feed to `AncestorIterators` constructors because
23 /// a PyErr can arise at each step of iteration, whereas our inner objects
38 /// a `PyErr` can arise at each step of iteration, whereas our inner objects
24 /// expect iterables over Revision, not over some Result<Revision, PyErr>
39 /// expect iterables over `Revision`, not over some `Result<Revision, PyErr>`
25 fn reviter_to_revvec(py: Python, revs: PyObject) -> PyResult<Vec<Revision>> {
40 fn reviter_to_revvec(py: Python, revs: PyObject) -> PyResult<Vec<Revision>> {
26 revs.iter(py)?
41 revs.iter(py)?
27 .map(|r| r.and_then(|o| o.extract::<Revision>(py)))
42 .map(|r| r.and_then(|o| o.extract::<Revision>(py)))
28 .collect()
43 .collect()
29 }
44 }
30
45
31 py_class!(class AncestorsIterator |py| {
46 py_class!(pub class AncestorsIterator |py| {
32 // TODO RW lock ?
47 // TODO RW lock ?
33 data inner: RefCell<Box<CoreIterator<Index>>>;
48 data inner: RefCell<Box<CoreIterator<Index>>>;
34
49
@@ -70,7 +85,7 b' impl AncestorsIterator {'
70 }
85 }
71 }
86 }
72
87
73 py_class!(class LazyAncestors |py| {
88 py_class!(pub class LazyAncestors |py| {
74 data inner: RefCell<Box<CoreLazy<Index>>>;
89 data inner: RefCell<Box<CoreLazy<Index>>>;
75
90
76 def __contains__(&self, rev: Revision) -> PyResult<bool> {
91 def __contains__(&self, rev: Revision) -> PyResult<bool> {
@@ -101,7 +116,7 b' py_class!(class LazyAncestors |py| {'
101
116
102 });
117 });
103
118
104 /// Create the module, with __package__ given from parent
119 /// Create the module, with `__package__` given from parent
105 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
120 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
106 let dotted_name = &format!("{}.ancestor", package);
121 let dotted_name = &format!("{}.ancestor", package);
107 let m = PyModule::new(py, dotted_name)?;
122 let m = PyModule::new(py, dotted_name)?;
@@ -1,3 +1,15 b''
1 // ancestors.rs
2 //
3 // Copyright 2018 Georges Racinet <gracinet@anybox.fr>
4 //
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
7
8 //! Bindings for Rust errors
9 //!
10 //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError`
11 //!
12 //! [`GraphError`]: struct.GraphError.html
1 use cpython::exc::ValueError;
13 use cpython::exc::ValueError;
2 use cpython::{PyErr, Python};
14 use cpython::{PyErr, Python};
3 use hg;
15 use hg;
@@ -12,7 +12,8 b''
12 //! it behaves as the `cext` package.
12 //! it behaves as the `cext` package.
13 //!
13 //!
14 //! Example:
14 //! Example:
15 //! ```
15 //!
16 //! ```text
16 //! >>> from mercurial.rustext import ancestor
17 //! >>> from mercurial.rustext import ancestor
17 //! >>> ancestor.__doc__
18 //! >>> ancestor.__doc__
18 //! 'Generic DAG ancestor algorithms - Rust implementation'
19 //! 'Generic DAG ancestor algorithms - Rust implementation'
@@ -23,9 +24,9 b' extern crate cpython;'
23 extern crate hg;
24 extern crate hg;
24 extern crate libc;
25 extern crate libc;
25
26
26 mod ancestors;
27 pub mod ancestors;
27 mod cindex;
28 mod cindex;
28 mod exceptions;
29 pub mod exceptions;
29
30
30 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
31 py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| {
31 m.add(
32 m.add(
General Comments 0
You need to be logged in to leave comments. Login now