// Copyright (c) 2017-present PyO3 Project and Contributors use std::rc::Rc; use std::marker::PhantomData; use err::PyResult; use pointers::Py; use python::Python; use typeob::{PyTypeInfo, PyObjectAlloc}; pub struct PyToken(PhantomData>); impl PyToken { pub fn token<'p>(&'p self) -> Python<'p> { unsafe { Python::assume_gil_acquired() } } } #[inline] pub fn with<'p, T, F>(py: Python<'p>, f: F) -> PyResult> where F: FnOnce(PyToken) -> T, T: PyTypeInfo + PyObjectAlloc { Py::new(py, f(PyToken(PhantomData))) } pub trait PyObjectWithToken : Sized { fn token<'p>(&'p self) -> Python<'p>; }