如何将rustcpython实现为_object()并实现为_object()?

2024-05-15 13:31:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为自定义类型实现traitPythonObject

impl PythonObject for PyTerm {
    #[inline]
    fn as_object(&self) -> &PyObject {
        //???
    }

    #[inline]
    fn into_object(self) -> PyObject {
        //???
    }

    #[inline]
    unsafe fn unchecked_downcast_from(o: PyObject) -> PyTerm {
        std::mem::transmute(o)
    }

    #[inline]
    unsafe fn unchecked_downcast_borrow_from(o: &PyObject) -> &PyTerm {
        std::mem::transmute(o)
    }
}

PyTerm定义为自定义结构:

struct PyTerm {
    // not important fields
}

Tags: fromself类型objectinlinememfnpyobject