diff options
| author | 2024-07-16 07:50:53 +0800 | |
|---|---|---|
| committer | 2024-07-16 07:50:53 +0800 | |
| commit | 4e827c1a26beffd71f80836197e981b82e447c21 (patch) | |
| tree | df56b1a1132f794c6d081dae461ad016eb1ab7d9 /src | |
| parent | fae8d2273dfad2dd0cf9709f15e24640e7ebfd8d (diff) | |
| download | HydroRollCore-4e827c1a26beffd71f80836197e981b82e447c21.tar.gz HydroRollCore-4e827c1a26beffd71f80836197e981b82e447c21.zip | |
style: Format python & rust code
Diffstat (limited to 'src')
| -rw-r--r-- | src/dev/mod.rs | 1 | ||||
| -rw-r--r-- | src/doc/mod.rs | 1 | ||||
| -rw-r--r-- | src/feat/mod.rs | 1 | ||||
| -rw-r--r-- | src/lib.rs | 59 | ||||
| -rw-r--r-- | src/perf/mod.rs | 2 |
5 files changed, 61 insertions, 3 deletions
diff --git a/src/dev/mod.rs b/src/dev/mod.rs index e69de29..8b13789 100644 --- a/src/dev/mod.rs +++ b/src/dev/mod.rs @@ -0,0 +1 @@ + diff --git a/src/doc/mod.rs b/src/doc/mod.rs index e69de29..8b13789 100644 --- a/src/doc/mod.rs +++ b/src/doc/mod.rs @@ -0,0 +1 @@ + diff --git a/src/feat/mod.rs b/src/feat/mod.rs index e69de29..8b13789 100644 --- a/src/feat/mod.rs +++ b/src/feat/mod.rs @@ -0,0 +1 @@ + @@ -1,3 +1,4 @@ +use clap::builder::Str; use pyo3::prelude::*; use pyo3::wrap_pyfunction; @@ -17,11 +18,65 @@ fn process_rule_pack(rule_pack: &str) -> PyResult<String> { Ok(format!("Processed rule pack: {}", rule_pack)) } -/// A Python module implemented in Rust. +#[pyclass] +struct Integer { + inner: i32, +} + +// A "tuple" struct +#[pyclass] +struct Number(i32); + +// PyO3 supports custom discriminants in enums +#[pyclass] +enum HttpResponse { + Ok = 200, + NotFound = 404, + Teapot = 418, + // ... +} + +use pyo3::exceptions::PyValueError; +use pyo3::prelude::*; +use pyo3::types::PyString; + +#[pyclass] +#[derive(Debug, Clone)] +enum RuleLoadType { + DIR, + NAME, + FILE, + CLASS, +} + +#[pymethods] +impl RuleLoadType { + #[staticmethod] + fn from_str(s: &str) -> PyResult<Self> { + match s { + "dir" => Ok(RuleLoadType::DIR), + "name" => Ok(RuleLoadType::NAME), + "file" => Ok(RuleLoadType::FILE), + "class" => Ok(RuleLoadType::CLASS), + _ => Err(PyValueError::new_err("Invalid value for RuleLoadType")), + } + } + + fn __str__(&self) -> PyResult<String> { + Ok(match self { + RuleLoadType::DIR => "dir", + RuleLoadType::NAME => "name", + RuleLoadType::FILE => "file", + RuleLoadType::CLASS => "class", + } + .to_string()) + } +} + #[pymodule] #[pyo3(name = "LibCore")] fn libcore(_py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(process_rule_pack, m)?)?; - perf::Asparagus; + m.add_class::<RuleLoadType>()?; Ok(()) } diff --git a/src/perf/mod.rs b/src/perf/mod.rs index 0444a3a..5dfb691 100644 --- a/src/perf/mod.rs +++ b/src/perf/mod.rs @@ -1 +1 @@ -pub struct Asparagus {}
\ No newline at end of file +pub struct Asparagus {} |
