Skip to content

Commit

Permalink
Showcase of PyO3/pyo3#340 and PyO3/pyo3#341.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvaled committed May 28, 2020
0 parents commit e7f940b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "pyo3bug"
version = "0.1.0"
authors = ["Manuel Vázquez Acosta <manuel@merchise.org>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "pyo3bug"
crate-type = ["cdylib"]


[dependencies.pyo3]
git = "https://github.com/PyO3/pyo3"
features = ["extension-module", "python3"]
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use pyo3::prelude::*;

#[pymodule]
fn pyo3bug(_py: Python, _m: &PyModule) -> PyResult<()> {
Ok(())
}

#[cfg(test)]
mod test {
use super::*;
use pyo3::types::{IntoPyDict, PyDateTime};

#[test]
fn pydelta_conversion() {
let gil = Python::acquire_gil();
let py = gil.python();
let datetime = py.import("datetime").unwrap();
let locals = [("datetime", datetime)].into_py_dict(py);
let now: &PyDateTime = py
.eval("datetime.datetime.utcnow()", None, Some(&locals))
.unwrap()
.downcast()
.unwrap();
println!("{:?}", now);
}
}

0 comments on commit e7f940b

Please sign in to comment.