diff --git a/examples/rustapi_module/src/lib.rs b/examples/rustapi_module/src/lib.rs index 98ca10fc..a3652764 100644 --- a/examples/rustapi_module/src/lib.rs +++ b/examples/rustapi_module/src/lib.rs @@ -25,10 +25,8 @@ fn get_date_tuple(py: Python, d: &PyDate) -> Py { } #[pyfunction] -fn date_from_timestamp(py: Python, ts: i64) -> PyResult> { - let timestamp = ts.to_object(py); - let args = PyTuple::new(py, &[timestamp]); - PyDate::from_timestamp(py, &args.to_object(py)) +fn date_from_timestamp(py: Python, timestamp: i64) -> PyResult> { + PyDate::from_timestamp(py, timestamp) } #[pyfunction] diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 0c0130a5..912c90d7 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -26,6 +26,7 @@ use ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD}; use instance::Py; use python::{Python, ToPyPointer}; +use types::PyTuple; // Traits pub trait PyDateAccess { @@ -66,7 +67,9 @@ impl PyDate { } } - pub fn from_timestamp(py: Python, args: &PyObject) -> PyResult> { + pub fn from_timestamp(py: Python, timestamp: i64) -> PyResult> { + let args = PyTuple::new(py, &[timestamp]); + unsafe { let ptr = (PyDateTimeAPI.Date_FromTimestamp)(PyDateTimeAPI.DateType, args.as_ptr()); Py::from_owned_ptr_or_err(py, ptr)