nice rust
This commit is contained in:
shenjack 2023-01-20 17:41:43 +08:00
parent 49158c0ae1
commit cc5840bef4
3 changed files with 27 additions and 5 deletions

View File

@ -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: ...

View File

@ -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)

View File

@ -6,11 +6,22 @@ fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
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(())
}