# pyo3::pyclass::PyClassAlloc - Rust
This trait enables custom `tp_new`/`tp_dealloc` implementations for `T: PyClass`.
Keywords: rust, rustlang, rust-lang, PyClassAlloc

# Trait pyo3::pyclass::PyClassAlloc [−] [src]

    pub trait PyClassAlloc: PyTypeInfo + Sized {
        unsafe fn new(
            py: Python<'_>,
            subtype: *mut PyTypeObject
        ) -> *mut Self::Layout { ... }
        unsafe fn dealloc(py: Python<'_>, self_: *mut Self::Layout) { ... }
    }

This trait enables custom `tp_new`/`tp_dealloc` implementations for `T: PyClass`.

## Provided methods

### `unsafe fn new(py: Python<'_>, subtype: *mut PyTypeObject) -> *mut Self::Layout` [src]

Allocate the actual field for `#[pyclass]`.

# Safety

This function must return a valid pointer to the Python heap.

### `unsafe fn dealloc(py: Python<'_>, self_: *mut Self::Layout)` [src]

Deallocate `#[pyclass]` on the Python heap.

# Safety

`self_` must be a valid pointer to the Python heap.

Loading content...

## Implementors

### `impl<T> PyClassAlloc for T where
T: PyTypeInfo + PyClassWithFreeList,` [src]

#### `unsafe fn new(py: Python<'_>, subtype: *mut PyTypeObject) -> *mut Self::Layout` [src]

#### `unsafe fn dealloc(py: Python<'_>, self_: *mut Self::Layout)` [src]

Loading content...