pyo3::impl_::pyclass

Trait OffsetCalculator

Source
pub unsafe trait OffsetCalculator<T: PyClass, U> {
    // Required method
    fn offset() -> usize;
}
Expand description

Helper trait to locate field within a #[pyclass] for a #[pyo3(get)].

Below MSRV 1.77 we can’t use std::mem::offset_of!, and the replacement in memoffset::offset_of doesn’t work in const contexts for types containing UnsafeCell.

§Safety

The trait is unsafe to implement because producing an incorrect offset will lead to UB.

Required Methods§

Source

fn offset() -> usize

Offset to the field within a PyClassObject<T>, in bytes.

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.

Implementors§

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here