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

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

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

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.

Implementors