Use AsRef/AsMut instead of as_super/as_super_mut
This commit is contained in:
parent
1f5cb83ef8
commit
3d0ee2a28d
|
@ -281,7 +281,7 @@ impl SubClass {
|
|||
}
|
||||
|
||||
fn method2(self_: PyRef<Self>) -> PyResult<usize> {
|
||||
let super_ = self_.as_super(); // Get &BaseClass
|
||||
let super_ = self_.as_ref(); // Get &BaseClass
|
||||
super_.method().map(|x| x * self_.val2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,11 +258,8 @@ pub struct PyRef<'p, T: PyClass> {
|
|||
inner: &'p PyCellInner<T>,
|
||||
}
|
||||
|
||||
impl<'p, T> PyRef<'p, T>
|
||||
where
|
||||
T: PyClass,
|
||||
{
|
||||
pub fn as_super(&self) -> &T::BaseType {
|
||||
impl<'p, T: PyClass> AsRef<T::BaseType> for PyRef<'p, T> {
|
||||
fn as_ref(&self) -> &T::BaseType {
|
||||
unsafe { self.inner.ob_base.unchecked_ref() }
|
||||
}
|
||||
}
|
||||
|
@ -326,11 +323,14 @@ pub struct PyRefMut<'p, T: PyClass> {
|
|||
inner: &'p PyCellInner<T>,
|
||||
}
|
||||
|
||||
impl<'p, T: PyClass> PyRefMut<'p, T> {
|
||||
pub fn as_super(&self) -> &T::BaseType {
|
||||
impl<'p, T: PyClass> AsRef<T::BaseType> for PyRefMut<'p, T> {
|
||||
fn as_ref(&self) -> &T::BaseType {
|
||||
unsafe { self.inner.ob_base.unchecked_ref() }
|
||||
}
|
||||
pub fn as_super_mut(&mut self) -> &mut T::BaseType {
|
||||
}
|
||||
|
||||
impl<'p, T: PyClass> AsMut<T::BaseType> for PyRefMut<'p, T> {
|
||||
fn as_mut(&mut self) -> &mut T::BaseType {
|
||||
unsafe { self.inner.ob_base.unchecked_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ fn inheritance_with_new_methods_with_drop() {
|
|||
let obj: &PyCell<SubClassWithDrop> = inst.try_into().unwrap();
|
||||
let mut obj_ref_mut = obj.borrow_mut();
|
||||
obj_ref_mut.data = Some(Arc::clone(&drop_called1));
|
||||
obj_ref_mut.as_super_mut().data = Some(Arc::clone(&drop_called2));
|
||||
obj_ref_mut.as_mut().data = Some(Arc::clone(&drop_called2));
|
||||
}
|
||||
|
||||
assert!(drop_called1.load(Ordering::Relaxed));
|
||||
|
|
Loading…
Reference in New Issue