diff --git a/libs/DR-rs/Difficult_Rocket_rs/__init__.pyi b/libs/DR-rs/Difficult_Rocket_rs/__init__.pyi new file mode 100644 index 0000000..a778b88 --- /dev/null +++ b/libs/DR-rs/Difficult_Rocket_rs/__init__.pyi @@ -0,0 +1,9 @@ +# ------------------------------- +# Difficult Rocket +# Copyright © 2021-2022 by shenjackyuanjie 3695888@qq.com +# All rights reserved +# ------------------------------- + +def sum_as_string(a: int, b: int) -> int: ... + +def for_x_in_range(a: int, b: int) -> None: ... diff --git a/libs/DR-rs/setup.py b/libs/DR-rs/setup.py index bb30ebc..a042091 100644 --- a/libs/DR-rs/setup.py +++ b/libs/DR-rs/setup.py @@ -3,14 +3,16 @@ # Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com # All rights reserved # ------------------------------- - +import sys from setuptools import setup from setuptools_rust import Binding, RustExtension setup( - name='Difficult_Rocket-rs', + name='Difficult_Rocket_rs', version='0.0.0.1', - rust_extensions=[RustExtension("Difficult_Rocket-rs.Difficult_Rocket-rs", binding=Binding.PyO3)], - packages=['Difficult_Rocket-rs'], + rust_extensions=[RustExtension("Difficult_Rocket_rs.Difficult_Rocket_rs", binding=Binding.PyO3)], + packages=['Difficult_Rocket_rs'], zip_safe=False ) + +print(sys.platform) diff --git a/libs/DR-rs/src/lib.rs b/libs/DR-rs/src/lib.rs index 92adf16..4bbc282 100644 --- a/libs/DR-rs/src/lib.rs +++ b/libs/DR-rs/src/lib.rs @@ -6,11 +6,22 @@ fn sum_as_string(a: usize, b: usize) -> PyResult { Ok((a + b).to_string()) } +#[pyfunction] +fn for_x_in_range(a: usize, b: usize) -> PyResult<()> { + assert!(a <= b); + for x in a..b { + println!("{}", x); + } + Ok(()) +} + /// A Python module implemented in Rust. The name of this function must match /// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to /// import the module. #[pymodule] -fn string_sum(_py: Python<'_>, m: &PyModule) -> PyResult<()> { +#[allow(non_snake_case)] +fn Difficult_Rocket_rs(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; + m.add_function(wrap_pyfunction!(for_x_in_range, m)?)?; Ok(()) } \ No newline at end of file