diff --git a/guide/src/module.md b/guide/src/module.md index 941836cb..94bd2eeb 100644 --- a/guide/src/module.md +++ b/guide/src/module.md @@ -29,9 +29,9 @@ use pyo3::{py, PyResult, Python, PyModule}; // add bindings to the generated python module // N.B: names: "librust2py" must be the name of the `.so` or `.pyd` file +/// This module is implemented in Rust. #[py::modinit(rust2py)] fn init_mod(py: Python, m: &PyModule) -> PyResult<()> { - m.add(py, "__doc__", "This module is implemented in Rust.")?; // pyo3 aware function. All of our python interface could be declared in a separate module. // Note that the `#[pyfn()]` annotation automatically converts the arguments from @@ -55,6 +55,16 @@ fn sum_as_string(a:i64, b:i64) -> String { The `modinit` procedural macro attribute takes care of exporting the initialization function of your module to Python. It takes one argument as the name of your module, it must be the name of the `.so` or `.pyd` file. +The [Rust doc comments](https://doc.rust-lang.org/stable/book/first-edition/comments.html) of the module initialization function will be applied automatically as the Python doc string of your module. + +```python +import rust2py + +print(rust2py.__doc__) +``` + +Which means that the above Python code will print `This module is implemented in Rust.`. + > On macOS, you will need to rename the output from `*.dylib` to `*.so`. > > On Windows, you will need to rename the output from `*.dll` to `*.pyd`. diff --git a/guide/src/overview.md b/guide/src/overview.md index d9607376..d7d66770 100644 --- a/guide/src/overview.md +++ b/guide/src/overview.md @@ -52,7 +52,7 @@ fn hello(py: Python) -> PyResult<()> { Example library with python bindings: The following two files will build with `cargo build`, and will generate a python-compatible library. -On Mac OS, you will need to rename the output from \*.dylib to \*.so. +On macOS, you will need to rename the output from \*.dylib to \*.so. On Windows, you will need to rename the output from \*.dll to \*.pyd. **`Cargo.toml`:** @@ -77,9 +77,9 @@ use pyo3::{py, PyResult, Python, PyModule}; // add bindings to the generated python module // N.B: names: "librust2py" must be the name of the `.so` or `.pyd` file +/// This module is implemented in Rust. #[py::modinit(rust2py)] fn init_mod(py: Python, m: &PyModule) -> PyResult<()> { - m.add(py, "__doc__", "This module is implemented in Rust.")?; #[pyfn(m, "sum_as_string")] // pyo3 aware function. All of our python interface could be declared in a separate module. diff --git a/src/lib.rs b/src/lib.rs index 73cad6ca..aaa392bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,7 +122,7 @@ //! ```bash //! cp ./target/debug/libhello.so ./hello.so //! ``` -//! (Note: on Mac OS you will have to rename `libhello.dynlib` to `libhello.so`) +//! (Note: on macOS you will have to rename `libhello.dynlib` to `libhello.so`) //! //! The extension module can then be imported into Python: //!