From dd873e954a92d0e3209fe98b034570b47c859589 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Wed, 12 Mar 2025 21:32:29 +0800 Subject: Initial commit --- src/lib.rs | 16 ++++++++++++++++ src/pyo3_template/__init__.py | 0 src/pyo3_template/__main__.py | 8 ++++++++ src/pyo3_template/_core.pyi | 3 +++ 4 files changed, 27 insertions(+) create mode 100644 src/lib.rs create mode 100644 src/pyo3_template/__init__.py create mode 100644 src/pyo3_template/__main__.py create mode 100644 src/pyo3_template/_core.pyi (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..166cb09 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,16 @@ +use pyo3::prelude::*; + +#[pyfunction] +fn sum_as_string(a: usize, b: usize) -> PyResult { + Ok((a + b).to_string()) +} + +#[pyclass] +pub struct Base {} + +#[pymodule] +fn _core(_py: Python<'_>, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; + m.add_class::()?; + Ok(()) +} \ No newline at end of file diff --git a/src/pyo3_template/__init__.py b/src/pyo3_template/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pyo3_template/__main__.py b/src/pyo3_template/__main__.py new file mode 100644 index 0000000..0135c6d --- /dev/null +++ b/src/pyo3_template/__main__.py @@ -0,0 +1,8 @@ +from ._core import sum_as_string + +def main(): + print(sum_as_string(1, 2)) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/pyo3_template/_core.pyi b/src/pyo3_template/_core.pyi new file mode 100644 index 0000000..4945a82 --- /dev/null +++ b/src/pyo3_template/_core.pyi @@ -0,0 +1,3 @@ +def sum_as_string(self, a: int, b: int) -> str: ... + +class Base: ... \ No newline at end of file -- cgit v1.2.3-70-g09d2