summary refs log tree commit diff
path: root/rust
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2022-09-06 19:01:37 +0100
committerGitHub <noreply@github.com>2022-09-06 19:01:37 +0100
commitc9b7e9735508bb148c6ad59c433d71e5b8b360ad (patch)
tree57ddf5996b62da73f12647f3b537f9843e4e8331 /rust
parentFix trial-olddeps (#13725) (diff)
downloadsynapse-c9b7e9735508bb148c6ad59c433d71e5b8b360ad.tar.xz
Add a stub Rust crate (#12595)
Diffstat (limited to 'rust')
-rw-r--r--rust/Cargo.toml21
-rw-r--r--rust/src/lib.rs15
2 files changed, 36 insertions, 0 deletions
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
new file mode 100644
index 0000000000..0a9760cafc
--- /dev/null
+++ b/rust/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+# We name the package `synapse` so that things like logging have the right
+# logging target.
+name = "synapse"
+
+# dummy version. See pyproject.toml for the Synapse's version number.
+version = "0.1.0"
+
+edition = "2021"
+rust-version = "1.61.0"
+
+[lib]
+name = "synapse"
+crate-type = ["cdylib"]
+
+[package.metadata.maturin]
+# This is where we tell maturin where to place the built library.
+name = "synapse.synapse_rust"
+
+[dependencies]
+pyo3 = { version = "0.16.5", features = ["extension-module", "macros", "abi3", "abi3-py37"] }
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
new file mode 100644
index 0000000000..fc4eb39154
--- /dev/null
+++ b/rust/src/lib.rs
@@ -0,0 +1,15 @@
+use pyo3::prelude::*;
+
+/// Formats the sum of two numbers as string.
+#[pyfunction]
+#[pyo3(text_signature = "(a, b, /)")]
+fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
+    Ok((a + b).to_string())
+}
+
+/// The entry point for defining the Python module.
+#[pymodule]
+fn synapse_rust(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
+    m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
+    Ok(())
+}