devel #73

Merged
PlexSheep merged 27 commits from devel into master 2024-03-01 21:20:30 +01:00
6 changed files with 38 additions and 10 deletions
Showing only changes of commit e8be5388b1 - Show all commits

View File

@ -54,12 +54,12 @@ categories.workspace = true
[features] [features]
default = ["log", "core"] default = ["log", "core"]
core = [] core = []
full = ["default", "core", "math", "log", "bintols", "net", "py"] full = ["default", "core", "math", "log", "bintols", "net"]
math = ["dep:libpt-math", "log"] math = ["dep:libpt-math", "log"]
log = ["dep:libpt-log"] log = ["dep:libpt-log"]
bintols = ["dep:libpt-bintols", "log"] bintols = ["dep:libpt-bintols", "log"]
net = ["dep:libpt-net", "log"] net = ["dep:libpt-net", "log"]
py = ["dep:libpt-py"] # py = ["dep:libpt-py"]
[lib] [lib]
name = "libpt" name = "libpt"
@ -75,4 +75,3 @@ libpt-bintols = { workspace = true, optional = true }
libpt-log = { workspace = true, optional = true } libpt-log = { workspace = true, optional = true }
libpt-math = { workspace = true, optional = true } libpt-math = { workspace = true, optional = true }
libpt-net = { workspace = true, optional = true } libpt-net = { workspace = true, optional = true }
libpt-py = { workspace = true, optional = true }

View File

@ -1,6 +1,6 @@
[package] [package]
name = "libpt-py" name = "libpt-py"
version = "0.3.11" version.workspace = true
edition.workspace = true edition.workspace = true
[package.metadata.maturin] [package.metadata.maturin]
@ -11,4 +11,14 @@ name = "libpt"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
libpt = { version = "0.3.11", path = "../.." }
pyo3 = "0.19.0" pyo3 = "0.19.0"
[features]
default = ["log", "core", "full"]
core = []
full = ["default", "core", "math", "log", "bintols", "net"]
math = ["libpt/math", "log"]
log = ["libpt/log"]
bintols = ["libpt/bintols", "log"]
net = ["libpt/net", "log"]

View File

@ -0,0 +1,11 @@
use pyo3::prelude::*;
/// implement a python module in Rust
#[pymodule]
#[pyo3(name = "core")]
pub fn submodule(py: Python, m: &PyModule) -> PyResult<()> {
let submodule = PyModule::new(py, "submodule")?;
submodule.add("super_useful_constant", "important")?;
m.add_submodule(m)?;
Ok(())
}

View File

@ -1,15 +1,23 @@
//! Python bindings for [`libpt`](libpt)
use libpt;
#[cfg(feature = "core")]
mod core;
use pyo3::prelude::*; use pyo3::prelude::*;
/// Formats the sum of two numbers as string. /// return the version of libpt
#[pyfunction] #[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> { fn version() -> String {
Ok((a + b).to_string()) env!("CARGO_PKG_VERSION").to_string()
} }
/// A Python module implemented in Rust. /// implement a python module in Rust
#[pymodule] #[pymodule]
#[pyo3(name = "libpt")] #[pyo3(name = "libpt")]
fn libpt_py(_py: Python, m: &PyModule) -> PyResult<()> { fn libpt_py(py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; m.add_function(wrap_pyfunction!(version, m)?)?;
#[cfg(feature = "core")]
core::submodule(py, m)?;
Ok(()) Ok(())
} }

View File

View File