Skip to content

Commit a4c2c4a

Browse files
committed
RUST language implemenation of IoText protocol
1 parent 72d6ad3 commit a4c2c4a

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "iotext"
3+
version = "0.1.0"
4+
rust-version = "1.57.0"
5+
6+
[lib]
7+
name = "_iotext"
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
pyo3 = { version = "0.19.0", features = ["auto-initialize", "extension-module"] }
12+
13+
# dependencies
14+
fancy-regex = "0.11.0"
15+
regex = "1.8.3"
16+
rustc-hash = "1.1.0"
17+
bstr = "1.5.0"
18+
19+
[profile.release]
20+
incremental = true

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
mypy
22
black==22.3.0
33
parameterized==0.9.0
4+
5+
# required for RUST development
6+
maturin==1.2.1

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This check is new and seems buggy (possibly with PyO3 interaction)
2+
#![allow(clippy::borrow_deref_ref)]
3+
4+
use pyo3::prelude::*;
5+
6+
/// Formats the sum of two numbers as string.
7+
#[pyfunction]
8+
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
9+
Ok((a + b).to_string())
10+
}
11+
12+
/// A Python module implemented in Rust. The name of this function must match
13+
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
14+
/// import the module.
15+
#[pymodule]
16+
fn string_sum(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
17+
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
18+
Ok(())
19+
}

0 commit comments

Comments
 (0)