-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust): wrap_pyfunction "process_rule_pack" in libcore module
- Loading branch information
1 parent
28a7b2e
commit 09413f0
Showing
8 changed files
with
82 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class libcore: | ||
"""Core library for hydro roll""" | ||
|
||
def __init__(self): ... | ||
def sum_as_string(self, a: int, b: int) -> str: | ||
"""sum two numbers and return the result as a string""" | ||
|
||
def process_rule_pack(rule_pack: str) -> str: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ requires = ["maturin>=1.4,<2.0"] | |
build-backend = "maturin" | ||
|
||
[project] | ||
name = "hydro_roll_core" | ||
name = "hydro-roll-core" | ||
dynamic = ["version"] | ||
description = "Core of HydroRoll SDK." | ||
authors = [{ name = "简律纯", email = "[email protected]" }] | ||
|
@@ -12,7 +12,7 @@ dependencies = [ | |
] | ||
requires-python = ">=3.9" | ||
readme = "README.rst" | ||
license = { text = "MIT" } | ||
license = { text = " AGPL-3.0" } | ||
|
||
[project.urls] | ||
homepage = "https://core.hydroroll.team/" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
use pyo3::prelude::*; | ||
use pyo3::wrap_pyfunction; | ||
|
||
/// Formats the sum of two numbers as string. | ||
#[pyfunction] | ||
fn sum_as_string(a: usize, b: usize) -> PyResult<String> { | ||
Ok((a + b).to_string()) | ||
fn process_rule_pack(rule_pack: &str) -> PyResult<String> { | ||
// 处理规则包的逻辑 | ||
Ok(format!("Processed rule pack: {}", rule_pack)) | ||
} | ||
|
||
/// A Python module implemented in Rust. | ||
#[pymodule] | ||
#[pyo3(name = "libcore")] | ||
fn corelib(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; | ||
fn libcore(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(process_rule_pack, m)?)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use lib::process_rule_pack; | ||
|
||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() < 2 { | ||
eprintln!("Usage: {} <rule_pack>", args[0]); | ||
std::process::exit(1); | ||
} | ||
match process_rule_pack(&args[1]) { | ||
Ok(result) => println!("Result: {}", result), | ||
Err(e) => eprintln!("Error: {}", e), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
from hydro_roll_core import libcore | ||
|
||
cb = libcore() | ||
cb.sum_as_string(1, 2) | ||
cb = libcore | ||
|
||
def main(): | ||
rule_pack = "example_rule_pack" | ||
result = cb.process_rule_pack(rule_pack) | ||
print(result) | ||
|
||
if __name__ == "__main__": | ||
main() |