view rust/hg-pyo3/src/lib.rs @ 52775:264047bf4b9b

rust-pyo3-revlog: new Python and Rust module We anticipate that we will actually need to organize the code in several Rust submodules, but it will of course still be exposed as a single Python module.
author Georges Racinet <georges.racinet@cloudcrane.io>
date Tue, 24 Dec 2024 18:02:11 +0100
parents 0f9ed7e7a71b
children 6fa23eed335b
line wrap: on
line source

use pyo3::prelude::*;

mod ancestors;
mod convert_cpython;
mod dagops;
mod exceptions;
mod revision;
mod revlog;
mod util;

#[pymodule]
fn pyo3_rustext(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
    m.add("__package__", "mercurial")?;
    m.add(
        "__doc__",
        "Mercurial core concepts - Rust implementation exposed via PyO3",
    )?;
    let dotted_name: String = m.getattr("__name__")?.extract()?;
    env_logger::init();

    m.add_submodule(&ancestors::init_module(py, &dotted_name)?)?;
    m.add_submodule(&dagops::init_module(py, &dotted_name)?)?;
    m.add_submodule(&revlog::init_module(py, &dotted_name)?)?;
    m.add("GraphError", py.get_type::<exceptions::GraphError>())?;
    Ok(())
}