Skip to content

Instantly share code, notes, and snippets.

@saethlin
Created September 6, 2017 23:31
Show Gist options
  • Save saethlin/f69bd2b8000dae4167b80224e3f88711 to your computer and use it in GitHub Desktop.
Save saethlin/f69bd2b8000dae4167b80224e3f88711 to your computer and use it in GitHub Desktop.
Demonstration of thread-safety enforced by Rust's type system
[package]
name = "typedemo"
version = "0.1.0"
authors = ["saethlin <[email protected]>"]
[dependencies.cpython]
version = "0.1"
features = ["extension-module"]
[lib]
crate-type = ["cdylib", "rlib"]
#[macro_use]
extern crate cpython;
use std::rc::Rc;
#[derive(Default)]
struct Example {
thing: Rc<u32>,
}
mod py_interface {
use cpython::PyResult;
use Example;
py_module_initializer!(example, initexample, PyInit_example, |py, m| {
m.add_class::<PyExample>(py)?;
Ok(())
});
py_class!(class PyExample |py| {
data ex: Example;
def __new__(_cls) -> PyResult<PyExample> {
PyExample::create_instance(py, Example::default())
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment