Skip to content

Commit 3d0ee2a

Browse files
committed
Use AsRef/AsMut instead of as_super/as_super_mut
1 parent 1f5cb83 commit 3d0ee2a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

guide/src/class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl SubClass {
281281
}
282282

283283
fn method2(self_: PyRef<Self>) -> PyResult<usize> {
284-
let super_ = self_.as_super(); // Get &BaseClass
284+
let super_ = self_.as_ref(); // Get &BaseClass
285285
super_.method().map(|x| x * self_.val2)
286286
}
287287
}

src/pycell.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,8 @@ pub struct PyRef<'p, T: PyClass> {
258258
inner: &'p PyCellInner<T>,
259259
}
260260

261-
impl<'p, T> PyRef<'p, T>
262-
where
263-
T: PyClass,
264-
{
265-
pub fn as_super(&self) -> &T::BaseType {
261+
impl<'p, T: PyClass> AsRef<T::BaseType> for PyRef<'p, T> {
262+
fn as_ref(&self) -> &T::BaseType {
266263
unsafe { self.inner.ob_base.unchecked_ref() }
267264
}
268265
}
@@ -326,11 +323,14 @@ pub struct PyRefMut<'p, T: PyClass> {
326323
inner: &'p PyCellInner<T>,
327324
}
328325

329-
impl<'p, T: PyClass> PyRefMut<'p, T> {
330-
pub fn as_super(&self) -> &T::BaseType {
326+
impl<'p, T: PyClass> AsRef<T::BaseType> for PyRefMut<'p, T> {
327+
fn as_ref(&self) -> &T::BaseType {
331328
unsafe { self.inner.ob_base.unchecked_ref() }
332329
}
333-
pub fn as_super_mut(&mut self) -> &mut T::BaseType {
330+
}
331+
332+
impl<'p, T: PyClass> AsMut<T::BaseType> for PyRefMut<'p, T> {
333+
fn as_mut(&mut self) -> &mut T::BaseType {
334334
unsafe { self.inner.ob_base.unchecked_mut() }
335335
}
336336
}

tests/test_gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn inheritance_with_new_methods_with_drop() {
268268
let obj: &PyCell<SubClassWithDrop> = inst.try_into().unwrap();
269269
let mut obj_ref_mut = obj.borrow_mut();
270270
obj_ref_mut.data = Some(Arc::clone(&drop_called1));
271-
obj_ref_mut.as_super_mut().data = Some(Arc::clone(&drop_called2));
271+
obj_ref_mut.as_mut().data = Some(Arc::clone(&drop_called2));
272272
}
273273

274274
assert!(drop_called1.load(Ordering::Relaxed));

0 commit comments

Comments
 (0)