pyo3_pytests/
othermod.rs

1//! <https://github.com/PyO3/pyo3/issues/233>
2//!
3//! The code below just tries to use the most important code generation paths
4
5use pyo3::prelude::*;
6
7#[pyclass]
8pub struct ModClass {
9    _somefield: String,
10}
11
12#[pymethods]
13impl ModClass {
14    #[new]
15    fn new() -> Self {
16        ModClass {
17            _somefield: String::from("contents"),
18        }
19    }
20
21    fn noop(&self, x: usize) -> usize {
22        x
23    }
24}
25
26#[pyfunction]
27fn double(x: i32) -> i32 {
28    x * 2
29}
30
31#[pymodule(gil_used = false)]
32pub fn othermod(m: &Bound<'_, PyModule>) -> PyResult<()> {
33    m.add_function(wrap_pyfunction!(double, m)?)?;
34
35    m.add_class::<ModClass>()?;
36
37    m.add("USIZE_MIN", usize::MIN)?;
38    m.add("USIZE_MAX", usize::MAX)?;
39
40    Ok(())
41}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here