[][src]Struct pyo3::typeob::PyRawObject

pub struct PyRawObject { /* fields omitted */ }

Special object that is used for python object creation. pyo3 library automatically creates this object for class __new__ method. Behavior is undefined if constructor of custom class does not initialze instance of PyRawObject with rust value with init method. Calling of __new__ method of base class is developer's responsibility.

Example of custom class implementation with __new__ method:

#![feature(specialization)]

use pyo3::prelude::*;

#[pyclass]
struct MyClass {
   token: PyToken
}

#[pymethods]
impl MyClass {
   #[new]
   fn __new__(obj: &PyRawObject) -> PyResult<()> {
       obj.init(|token| MyClass { token })
   }
}

Methods

impl PyRawObject[src]

#[must_use]
pub unsafe fn new(
    py: Python,
    tp_ptr: *mut PyTypeObject,
    curr_ptr: *mut PyTypeObject
) -> PyResult<PyRawObject>
[src]

#[must_use]
pub unsafe fn new_with_ptr(
    py: Python,
    ptr: *mut PyObject,
    tp_ptr: *mut PyTypeObject,
    curr_ptr: *mut PyTypeObject
) -> PyResult<PyRawObject>
[src]

pub fn init<T, F>(&self, f: F) -> PyResult<()> where
    F: FnOnce(PyToken) -> T,
    T: PyTypeInfo
[src]

pub fn type_object(&self) -> &PyType[src]

Type object

Trait Implementations

impl PyObjectWithToken for PyRawObject[src]

impl IntoPyPointer for PyRawObject[src]

impl<T: PyTypeInfo> AsRef<T> for PyRawObject[src]

Auto Trait Implementations

impl !Send for PyRawObject

impl !Sync for PyRawObject

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.