Skip to content

Commit da9eb2a

Browse files
committed
add pyO3 module
1 parent fc1ec00 commit da9eb2a

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed

python/tskit_glue/Cargo.lock

Lines changed: 171 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/tskit_glue/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "tskit_glue"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
[lib]
8+
name = "tskit_glue"
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
pyo3 = "0.24.0"

python/tskit_glue/pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build-system]
2+
requires = ["maturin>=1.8,<2.0"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "tskit_glue"
7+
requires-python = ">=3.8"
8+
classifiers = [
9+
"Programming Language :: Rust",
10+
"Programming Language :: Python :: Implementation :: CPython",
11+
"Programming Language :: Python :: Implementation :: PyPy",
12+
]
13+
dynamic = ["version"]
14+
[tool.maturin]
15+
features = ["pyo3/extension-module"]

python/tskit_glue/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use pyo3::prelude::*;
2+
3+
/// Formats the sum of two numbers as string.
4+
#[pyfunction]
5+
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
6+
Ok((a + b).to_string())
7+
}
8+
9+
/// A Python module implemented in Rust.
10+
#[pymodule]
11+
fn tskit_glue(m: &Bound<'_, PyModule>) -> PyResult<()> {
12+
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
13+
Ok(())
14+
}

0 commit comments

Comments
 (0)