Created
September 6, 2017 23:31
-
-
Save saethlin/f69bd2b8000dae4167b80224e3f88711 to your computer and use it in GitHub Desktop.
Demonstration of thread-safety enforced by Rust's type system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "typedemo" | |
version = "0.1.0" | |
authors = ["saethlin <[email protected]>"] | |
[dependencies.cpython] | |
version = "0.1" | |
features = ["extension-module"] | |
[lib] | |
crate-type = ["cdylib", "rlib"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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