Trait cpython::py_class::BaseObject

source ·
pub trait BaseObject: PythonObject {
    type InitType;

    // Required methods
    fn size() -> usize;
    unsafe fn alloc(
        py: Python<'_>,
        ty: &PyType,
        init_val: Self::InitType
    ) -> PyResult<PyObject>;
    unsafe fn dealloc(py: Python<'_>, obj: *mut PyObject);
}
Expand description

A PythonObject that is usable as a base type with the py_class!() macro.

Required Associated Types§

Required Methods§

source

fn size() -> usize

Gets the size of the object, in bytes.

source

unsafe fn alloc( py: Python<'_>, ty: &PyType, init_val: Self::InitType ) -> PyResult<PyObject>

Allocates a new object (usually by calling ty->tp_alloc), and initializes it using init_val. ty must be derived from the Self type, and the resulting object must be of type ty.

source

unsafe fn dealloc(py: Python<'_>, obj: *mut PyObject)

Calls the rust destructor for the object and frees the memory (usually by calling ptr->ob_type->tp_free). This function is used as tp_dealloc implementation.

Object Safety§

This trait is not object safe.

Implementors§