# HG changeset patch # User Georges Racinet # Date 2018-12-22 10:38:03 # Node ID dcf818267bc1d911b9ddf120b8fa093db00e3299 # Parent c01fac6749e51aa2a578781bab652c2bd5728708 rust-cpython: rustdoc improvements By default, `cargo doc` builds the documentation for public constructs only, so we make public those that can. Since `cindex` is not safe, we keep it private. Unfortunately, the macro syntax of rust-cpython doesn't allow us to document the classes directly, so we resort to do that at the module level. Differential Revision: https://phab.mercurial-scm.org/D5546 diff --git a/rust/hg-cpython/src/ancestors.rs b/rust/hg-cpython/src/ancestors.rs --- a/rust/hg-cpython/src/ancestors.rs +++ b/rust/hg-cpython/src/ancestors.rs @@ -5,8 +5,23 @@ // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. -//! Bindings for the hg::ancestors module provided by the +//! Bindings for the `hg::ancestors` module provided by the //! `hg-core` crate. From Python, this will be seen as `rustext.ancestor` +//! and can be used as replacement for the the pure `ancestor` Python module. +//! +//! # Classes visible from Python: +//! - [`LazyAncestors`] is the Rust implementation of +//! `mercurial.ancestor.lazyancestors`. +//! The only difference is that it is instantiated with a C `parsers.index` +//! instance instead of a parents function. +//! +//! - [`AncestorsIterator`] is the Rust counterpart of the +//! `ancestor._lazyancestorsiter` Python generator. +//! From Python, instances of this should be mainly obtained by calling +//! `iter()` on a [`LazyAncestors`] instance. +//! +//! [`LazyAncestors`]: struct.LazyAncestors.html +//! [`AncestorsIterator`]: struct.AncestorsIterator.html use cindex::Index; use cpython::{ ObjectProtocol, PyClone, PyDict, PyModule, PyObject, PyResult, Python, @@ -19,16 +34,16 @@ use std::cell::RefCell; /// Utility function to convert a Python iterable into a Vec /// -/// We need this to feed to AncestorIterators constructors because -/// a PyErr can arise at each step of iteration, whereas our inner objects -/// expect iterables over Revision, not over some Result +/// We need this to feed to `AncestorIterators` constructors because +/// a `PyErr` can arise at each step of iteration, whereas our inner objects +/// expect iterables over `Revision`, not over some `Result` fn reviter_to_revvec(py: Python, revs: PyObject) -> PyResult> { revs.iter(py)? .map(|r| r.and_then(|o| o.extract::(py))) .collect() } -py_class!(class AncestorsIterator |py| { +py_class!(pub class AncestorsIterator |py| { // TODO RW lock ? data inner: RefCell>>; @@ -70,7 +85,7 @@ impl AncestorsIterator { } } -py_class!(class LazyAncestors |py| { +py_class!(pub class LazyAncestors |py| { data inner: RefCell>>; def __contains__(&self, rev: Revision) -> PyResult { @@ -101,7 +116,7 @@ py_class!(class LazyAncestors |py| { }); -/// Create the module, with __package__ given from parent +/// Create the module, with `__package__` given from parent pub fn init_module(py: Python, package: &str) -> PyResult { let dotted_name = &format!("{}.ancestor", package); let m = PyModule::new(py, dotted_name)?; diff --git a/rust/hg-cpython/src/exceptions.rs b/rust/hg-cpython/src/exceptions.rs --- a/rust/hg-cpython/src/exceptions.rs +++ b/rust/hg-cpython/src/exceptions.rs @@ -1,3 +1,15 @@ +// ancestors.rs +// +// Copyright 2018 Georges Racinet +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +//! Bindings for Rust errors +//! +//! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError` +//! +//! [`GraphError`]: struct.GraphError.html use cpython::exc::ValueError; use cpython::{PyErr, Python}; use hg; diff --git a/rust/hg-cpython/src/lib.rs b/rust/hg-cpython/src/lib.rs --- a/rust/hg-cpython/src/lib.rs +++ b/rust/hg-cpython/src/lib.rs @@ -12,7 +12,8 @@ //! it behaves as the `cext` package. //! //! Example: -//! ``` +//! +//! ```text //! >>> from mercurial.rustext import ancestor //! >>> ancestor.__doc__ //! 'Generic DAG ancestor algorithms - Rust implementation' @@ -23,9 +24,9 @@ extern crate cpython; extern crate hg; extern crate libc; -mod ancestors; +pub mod ancestors; mod cindex; -mod exceptions; +pub mod exceptions; py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| { m.add(