\pyo3/
nice rust
This commit is contained in:
parent
49158c0ae1
commit
cc5840bef4
9
libs/DR-rs/Difficult_Rocket_rs/__init__.pyi
Normal file
9
libs/DR-rs/Difficult_Rocket_rs/__init__.pyi
Normal 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: ...
|
@ -3,14 +3,16 @@
|
|||||||
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
||||||
# All rights reserved
|
# All rights reserved
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
import sys
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from setuptools_rust import Binding, RustExtension
|
from setuptools_rust import Binding, RustExtension
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='Difficult_Rocket-rs',
|
name='Difficult_Rocket_rs',
|
||||||
version='0.0.0.1',
|
version='0.0.0.1',
|
||||||
rust_extensions=[RustExtension("Difficult_Rocket-rs.Difficult_Rocket-rs", binding=Binding.PyO3)],
|
rust_extensions=[RustExtension("Difficult_Rocket_rs.Difficult_Rocket_rs", binding=Binding.PyO3)],
|
||||||
packages=['Difficult_Rocket-rs'],
|
packages=['Difficult_Rocket_rs'],
|
||||||
zip_safe=False
|
zip_safe=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(sys.platform)
|
||||||
|
@ -6,11 +6,22 @@ fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
|
|||||||
Ok((a + b).to_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
|
/// 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
|
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
|
||||||
/// import the module.
|
/// import the module.
|
||||||
#[pymodule]
|
#[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!(sum_as_string, m)?)?;
|
||||||
|
m.add_function(wrap_pyfunction!(for_x_in_range, m)?)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user