pub trait PyPayload:
MaybeTraverse
+ PyThreadingConstraint
+ Sized
+ 'static {
const PAYLOAD_TYPE_ID: TypeId = _;
const HAS_FREELIST: bool = false;
const MAX_FREELIST: usize = 0;
// Required method
fn class(ctx: &Context) -> &'static Py<PyType>;
// Provided methods
unsafe fn validate_downcastable_from(_obj: &PyObject) -> bool { ... }
fn try_downcast_from(obj: &PyObject, vm: &VirtualMachine) -> PyResult<()> { ... }
unsafe fn freelist_push(_obj: *mut PyObject) -> bool { ... }
unsafe fn freelist_pop(_payload: &Self) -> Option<NonNull<PyObject>> { ... }
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRef
where Self: Debug { ... }
fn _into_ref(self, cls: PyTypeRef, ctx: &Context) -> PyRef<Self>
where Self: Debug { ... }
fn into_exact_ref(self, ctx: &Context) -> PyRefExact<Self>
where Self: Debug { ... }
fn into_ref(self, ctx: &Context) -> PyRef<Self>
where Self: Debug { ... }
fn into_ref_with_type(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>
where Self: Debug { ... }
}Provided Associated Constants§
const PAYLOAD_TYPE_ID: TypeId = _
Sourceconst HAS_FREELIST: bool = false
const HAS_FREELIST: bool = false
Whether this type has a freelist. Types with freelists require immediate (non-deferred) GC untracking during dealloc to prevent race conditions when the object is reused.
Sourceconst MAX_FREELIST: usize = 0
const MAX_FREELIST: usize = 0
Maximum number of objects to keep in the freelist.
Required Methods§
Provided Methods§
Sourceunsafe fn validate_downcastable_from(_obj: &PyObject) -> bool
unsafe fn validate_downcastable_from(_obj: &PyObject) -> bool
§Safety
This function should only be called if payload_type_id matches the type of obj.
fn try_downcast_from(obj: &PyObject, vm: &VirtualMachine) -> PyResult<()>
Sourceunsafe fn freelist_push(_obj: *mut PyObject) -> bool
unsafe fn freelist_push(_obj: *mut PyObject) -> bool
Try to push a dead object onto this type’s freelist for reuse. Returns true if the object was stored (caller must NOT free the memory). Called before tp_clear, so the payload is still intact.
§Safety
obj must be a valid pointer to a PyInner<Self> with refcount 0.
The payload is still initialized and can be read for bucket selection.
Sourceunsafe fn freelist_pop(_payload: &Self) -> Option<NonNull<PyObject>>
unsafe fn freelist_pop(_payload: &Self) -> Option<NonNull<PyObject>>
Try to pop a pre-allocated object from this type’s freelist.
The returned pointer still has the old payload; the caller must
reinitialize ref_count, gc_bits, and payload.
§Safety
The returned pointer (if Some) must point to a valid PyInner<Self>
whose payload is still initialized from a previous allocation. The caller
will drop and overwrite payload before reuse.
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRefwhere
Self: Debug,
fn _into_ref(self, cls: PyTypeRef, ctx: &Context) -> PyRef<Self>where
Self: Debug,
fn into_exact_ref(self, ctx: &Context) -> PyRefExact<Self>where
Self: Debug,
fn into_ref(self, ctx: &Context) -> PyRef<Self>where
Self: Debug,
fn into_ref_with_type(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>where
Self: Debug,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.