pub struct PyRef<'p, T>where
    T: PyClass,{ /* private fields */ }Expand description
A wrapper type for an immutably borrowed value from a PyCell<T>.
See the PyCell documentation for more information.
Examples
You can use PyRef as an alternative to a &self receiver when
- you need to access the pointer of the 
PyCell, or - you want to get a super class.
 
#[pyclass(subclass)]
struct Parent {
    basename: &'static str,
}
#[pyclass(extends=Parent)]
struct Child {
    name: &'static str,
 }
#[pymethods]
impl Child {
    #[new]
    fn new() -> (Self, Parent) {
        (Child { name: "Caterpillar" }, Parent { basename: "Butterfly" })
    }
    fn format(slf: PyRef<'_, Self>) -> String {
        // We can get *mut ffi::PyObject from PyRef
        use pyo3::AsPyPointer;
        let refcnt = unsafe { pyo3::ffi::Py_REFCNT(slf.as_ptr()) };
        // We can get &Self::BaseType by as_ref
        let basename = slf.as_ref().basename;
        format!("{}(base: {}, cnt: {})", slf.name, basename, refcnt)
    }
}See the module-level documentation for more information.
Implementations
sourceimpl<'p, T, U> PyRef<'p, T>where
    T: PyClass<BaseType = U>,
    U: PyClass,
 
impl<'p, T, U> PyRef<'p, T>where
    T: PyClass<BaseType = U>,
    U: PyClass,
sourcepub fn into_super(self) -> PyRef<'p, U>
 
pub fn into_super(self) -> PyRef<'p, U>
Gets a PyRef<T::BaseType>.
While as_ref() returns a reference of type &T::BaseType, this cannot be
used to get the base of T::BaseType.
But with the help of this method, you can get hold of instances of the super-superclass when needed.
Examples
#[pyclass(subclass)]
struct Base1 {
    name1: &'static str,
}
#[pyclass(extends=Base1, subclass)]
struct Base2 {
    name2: &'static str,
}
#[pyclass(extends=Base2)]
struct Sub {
    name3: &'static str,
}
#[pymethods]
impl Sub {
    #[new]
    fn new() -> PyClassInitializer<Self> {
        PyClassInitializer::from(Base1 { name1: "base1" })
            .add_subclass(Base2 { name2: "base2" })
            .add_subclass(Self { name3: "sub" })
    }
    fn name(slf: PyRef<'_, Self>) -> String {
        let subname = slf.name3;
        let super_ = slf.into_super();
        format!("{} {} {}", super_.as_ref().name1, super_.name2, subname)
    }
}Trait Implementations
sourceimpl<'a, T> AsPyPointer for PyRef<'a, T>where
    T: PyClass,
 
impl<'a, T> AsPyPointer for PyRef<'a, T>where
    T: PyClass,
sourceimpl<'a, T> FromPyObject<'a> for PyRef<'a, T>where
    T: PyClass,
 
impl<'a, T> FromPyObject<'a> for PyRef<'a, T>where
    T: PyClass,
Auto Trait Implementations
impl<'p, T> !RefUnwindSafe for PyRef<'p, T>
impl<'p, T> !Send for PyRef<'p, T>
impl<'p, T> !Sync for PyRef<'p, T>
impl<'p, T> Unpin for PyRef<'p, T>
impl<'p, T> !UnwindSafe for PyRef<'p, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
 
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToHex for Twhere
    T: AsRef<[u8]>,
 
impl<T> ToHex for Twhere
    T: AsRef<[u8]>,
sourcefn encode_hex<U>(&self) -> Uwhere
    U: FromIterator<char>,
 
fn encode_hex<U>(&self) -> Uwhere
    U: FromIterator<char>,
Encode the hex strict representing 
self into the result. Lower case
letters are used (e.g. f9b4ca) Read moresourcefn encode_hex_upper<U>(&self) -> Uwhere
    U: FromIterator<char>,
 
fn encode_hex_upper<U>(&self) -> Uwhere
    U: FromIterator<char>,
Encode the hex strict representing 
self into the result. Upper case
letters are used (e.g. F9B4CA) Read more