Trait cpython::ToPyObject
[−]
[src]
pub trait ToPyObject { type ObjectType: PythonObject; fn to_py_object(&self, py: Python) -> Self::ObjectType; fn into_py_object(self, py: Python) -> Self::ObjectType
where
Self: Sized, { ... } fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
where
F: FnOnce(*mut PyObject) -> R, { ... } }
Conversion trait that allows various objects to be converted into Python objects.
Associated Types
type ObjectType: PythonObject
Required Methods
fn to_py_object(&self, py: Python) -> Self::ObjectType
Converts self into a Python object.
Provided Methods
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
Self: Sized,
Converts self into a Python object.
May be more efficient than to_py_object
in some cases because
it can move out of the input object.
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
F: FnOnce(*mut PyObject) -> R,
Converts self into a Python object and calls the specified closure on the native FFI pointer underlying the Python object.
May be more efficient than to_py_object
because it does not need
to touch any reference counts when the input object already is a Python object.
Implementations on Foreign Types
impl<'a, T: ?Sized> ToPyObject for &'a T where
T: ToPyObject,
[src]
T: ToPyObject,
type ObjectType = T::ObjectType
fn to_py_object(&self, py: Python) -> T::ObjectType
[src]
fn into_py_object(self, py: Python) -> T::ObjectType
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<T> ToPyObject for Option<T> where
T: ToPyObject,
[src]
T: ToPyObject,
Option::Some<T>
is converted like T
.
Option::None
is converted to Python None
.
type ObjectType = PyObject
fn to_py_object(&self, py: Python) -> PyObject
[src]
fn into_py_object(self, py: Python) -> PyObject
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for str
[src]
Converts Rust str
to Python object.
See PyString::new
for details on the conversion.
type ObjectType = PyString
fn to_py_object(&self, py: Python) -> PyString
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<'a> ToPyObject for Cow<'a, str>
[src]
Converts Rust Cow<str>
to Python object.
See PyString::new
for details on the conversion.
type ObjectType = PyString
fn to_py_object(&self, py: Python) -> PyString
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for String
[src]
Converts Rust String
to Python object.
See PyString::new
for details on the conversion.
type ObjectType = PyString
fn to_py_object(&self, py: Python) -> PyString
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<K, V, H> ToPyObject for HashMap<K, V, H> where
K: Hash + Eq + ToPyObject,
V: ToPyObject,
H: BuildHasher,
[src]
K: Hash + Eq + ToPyObject,
V: ToPyObject,
H: BuildHasher,
type ObjectType = PyDict
fn to_py_object(&self, py: Python) -> PyDict
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<K, V> ToPyObject for BTreeMap<K, V> where
K: Eq + ToPyObject,
V: ToPyObject,
[src]
K: Eq + ToPyObject,
V: ToPyObject,
type ObjectType = PyDict
fn to_py_object(&self, py: Python) -> PyDict
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for bool
[src]
Converts a rust bool
to a Python bool
.
type ObjectType = PyBool
fn to_py_object(&self, py: Python) -> PyBool
[src]
fn with_borrowed_ptr<F, R>(&self, _py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
impl<A: ToPyObject> ToPyObject for (A,)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject> ToPyObject for (A, B)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject, C: ToPyObject> ToPyObject for (A, B, C)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject> ToPyObject for (A, B, C, D)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject> ToPyObject for (A, B, C, D, E)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject> ToPyObject for (A, B, C, D, E, F)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject, G: ToPyObject> ToPyObject for (A, B, C, D, E, F, G)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject, G: ToPyObject, H: ToPyObject> ToPyObject for (A, B, C, D, E, F, G, H)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<A: ToPyObject, B: ToPyObject, C: ToPyObject, D: ToPyObject, E: ToPyObject, F: ToPyObject, G: ToPyObject, H: ToPyObject, I: ToPyObject> ToPyObject for (A, B, C, D, E, F, G, H, I)
[src]
type ObjectType = PyTuple
fn to_py_object(&self, py: Python) -> PyTuple
[src]
fn into_py_object(self, py: Python) -> PyTuple
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<T> ToPyObject for [T] where
T: ToPyObject,
[src]
T: ToPyObject,
type ObjectType = PyList
fn to_py_object(&self, py: Python) -> PyList
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<T> ToPyObject for Vec<T> where
T: ToPyObject,
[src]
T: ToPyObject,
type ObjectType = PyList
fn to_py_object(&self, py: Python) -> PyList
[src]
fn into_py_object(self, py: Python) -> PyList
[src]
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for i8
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for u8
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for i16
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for u16
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for i32
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for u32
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for i64
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for isize
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for usize
[src]
type ObjectType = <u64 as ToPyObject>::ObjectType
fn to_py_object(&self, py: Python) -> <u64 as ToPyObject>::ObjectType
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl<'p> ToPyObject for u64
[src]
type ObjectType = PyLong
fn to_py_object(&self, py: Python) -> PyLong
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for f64
[src]
type ObjectType = PyFloat
fn to_py_object(&self, py: Python) -> PyFloat
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
impl ToPyObject for f32
[src]
type ObjectType = PyFloat
fn to_py_object(&self, py: Python) -> PyFloat
[src]
fn into_py_object(self, py: Python) -> Self::ObjectType where
Self: Sized,
[src]
Self: Sized,
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
Implementors
impl ToPyObject for PyObject type ObjectType = PyObject;
impl ToPyObject for PyType type ObjectType = PyType;
impl ToPyObject for PyModule type ObjectType = PyModule;
impl ToPyObject for PyString type ObjectType = PyString;
impl ToPyObject for PyBytes type ObjectType = PyBytes;
impl ToPyObject for PyDict type ObjectType = PyDict;
impl ToPyObject for PyBool type ObjectType = PyBool;
impl ToPyObject for PyTuple type ObjectType = PyTuple;
impl ToPyObject for NoArgs type ObjectType = PyTuple;
impl ToPyObject for PyList type ObjectType = PyList;
impl ToPyObject for PyLong type ObjectType = PyLong;
impl ToPyObject for PyFloat type ObjectType = PyFloat;
impl ToPyObject for PySequence type ObjectType = PySequence;
impl ToPyObject for BaseException type ObjectType = BaseException;
impl ToPyObject for Exception type ObjectType = Exception;
impl ToPyObject for LookupError type ObjectType = LookupError;
impl ToPyObject for AssertionError type ObjectType = AssertionError;
impl ToPyObject for AttributeError type ObjectType = AttributeError;
impl ToPyObject for EOFError type ObjectType = EOFError;
impl ToPyObject for EnvironmentError type ObjectType = EnvironmentError;
impl ToPyObject for FloatingPointError type ObjectType = FloatingPointError;
impl ToPyObject for IOError type ObjectType = IOError;
impl ToPyObject for ImportError type ObjectType = ImportError;
impl ToPyObject for IndexError type ObjectType = IndexError;
impl ToPyObject for KeyError type ObjectType = KeyError;
impl ToPyObject for KeyboardInterrupt type ObjectType = KeyboardInterrupt;
impl ToPyObject for MemoryError type ObjectType = MemoryError;
impl ToPyObject for NameError type ObjectType = NameError;
impl ToPyObject for NotImplementedError type ObjectType = NotImplementedError;
impl ToPyObject for OSError type ObjectType = OSError;
impl ToPyObject for OverflowError type ObjectType = OverflowError;
impl ToPyObject for ReferenceError type ObjectType = ReferenceError;
impl ToPyObject for RuntimeError type ObjectType = RuntimeError;
impl ToPyObject for SyntaxError type ObjectType = SyntaxError;
impl ToPyObject for SystemError type ObjectType = SystemError;
impl ToPyObject for SystemExit type ObjectType = SystemExit;
impl ToPyObject for TypeError type ObjectType = TypeError;
impl ToPyObject for ValueError type ObjectType = ValueError;
impl ToPyObject for ZeroDivisionError type ObjectType = ZeroDivisionError;
impl ToPyObject for BufferError type ObjectType = BufferError;
impl ToPyObject for UnicodeDecodeError type ObjectType = UnicodeDecodeError;
impl ToPyObject for UnicodeEncodeError type ObjectType = UnicodeEncodeError;
impl ToPyObject for UnicodeTranslateError type ObjectType = UnicodeTranslateError;