@@ -29,12 +29,12 @@ pub struct PyCellBase<T> {
29
29
30
30
unsafe impl < T , U > PyLayout < T > for PyCellBase < U > where U : PySizedLayout < T > { }
31
31
32
- /// `PyCell` is the container type for [`PyClass`](../pyclass/trait.PyClass.html).
32
+ /// `PyCell` is the container type for [`PyClass`](../pyclass/trait.PyClass.html) values .
33
33
///
34
- /// From Python side, `PyCell<T>` is the concrete layout of `T: PyClass` in the Python heap,
34
+ /// From the Python side, `PyCell<T>` is the concrete layout of `T: PyClass` in the Python heap,
35
35
/// which means we can convert `*const PyClass<T>` to `*mut ffi::PyObject`.
36
36
///
37
- /// From Rust side, `PyCell<T>` is the mutable container of `T`.
37
+ /// From the Rust side, `PyCell<T>` is the mutable container of `T`.
38
38
/// Since `PyCell<T: PyClass>` is always on the Python heap, we don't have the ownership of it.
39
39
/// Thus, to mutate the data behind `&PyCell<T>` safely, we employ the
40
40
/// [Interior Mutability Pattern](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html)
@@ -46,7 +46,7 @@ unsafe impl<T, U> PyLayout<T> for PyCellBase<U> where U: PySizedLayout<T> {}
46
46
/// # Examples
47
47
///
48
48
/// In most cases, `PyCell` is hidden behind `#[pymethods]`.
49
- /// However, you can construct `&PyCell` directly to test your pyclass in Rust code.
49
+ /// However, you can construct a `&PyCell` directly to test your pyclass in Rust code.
50
50
///
51
51
/// ```
52
52
/// # use pyo3::prelude::*;
@@ -67,7 +67,7 @@ unsafe impl<T, U> PyLayout<T> for PyCellBase<U> where U: PySizedLayout<T> {}
67
67
/// });
68
68
/// ```
69
69
/// You can use `slf: &PyCell<Self>` as an alternative `self` receiver of `#[pymethod]`,
70
- /// though you rarely need it.
70
+ /// though you'll rarely need it.
71
71
/// ```
72
72
/// # use pyo3::prelude::*;
73
73
/// use std::collections::HashMap;
@@ -189,7 +189,7 @@ impl<T: PyClass> PyCell<T> {
189
189
unsafe impl < T : PyClass > PyNativeType for PyCell < T > { }
190
190
191
191
impl < T : PyClass > PyCell < T > {
192
- /// Make a new `PyCell` on the Python heap and return the reference to it.
192
+ /// Makes a new `PyCell` on the Python heap and return the reference to it.
193
193
///
194
194
/// In cases where the value in the cell does not need to be accessed immediately after
195
195
/// creation, consider [`Py::new`](../instance/struct.Py.html#method.new) as a more efficient
@@ -202,7 +202,7 @@ impl<T: PyClass> PyCell<T> {
202
202
}
203
203
}
204
204
205
- /// Immutably borrows the value `T`. This borrow lasts untill the returned `PyRef` exists.
205
+ /// Immutably borrows the value `T`. This borrow lasts as long as the returned `PyRef` exists.
206
206
///
207
207
/// # Panics
208
208
///
@@ -212,7 +212,7 @@ impl<T: PyClass> PyCell<T> {
212
212
self . try_borrow ( ) . expect ( "Already mutably borrowed" )
213
213
}
214
214
215
- /// Mutably borrows the value `T`. This borrow lasts untill the returned `PyRefMut` exists.
215
+ /// Mutably borrows the value `T`. This borrow lasts as long as the returned `PyRefMut` exists.
216
216
///
217
217
/// # Panics
218
218
///
@@ -223,7 +223,7 @@ impl<T: PyClass> PyCell<T> {
223
223
}
224
224
225
225
/// Immutably borrows the value `T`, returning an error if the value is currently
226
- /// mutably borrowed. This borrow lasts untill the returned `PyRef` exists.
226
+ /// mutably borrowed. This borrow lasts as long as the returned `PyRef` exists.
227
227
///
228
228
/// This is the non-panicking variant of [`borrow`](#method.borrow).
229
229
///
@@ -257,7 +257,7 @@ impl<T: PyClass> PyCell<T> {
257
257
}
258
258
259
259
/// Mutably borrows the value `T`, returning an error if the value is currently borrowed.
260
- /// This borrow lasts untill the returned `PyRefMut` exists.
260
+ /// This borrow lasts as long as the returned `PyRefMut` exists.
261
261
///
262
262
/// This is the non-panicking variant of [`borrow_mut`](#method.borrow_mut).
263
263
///
@@ -323,7 +323,7 @@ impl<T: PyClass> PyCell<T> {
323
323
}
324
324
}
325
325
326
- /// Replaces the wrapped value with a new one, returning the old value,
326
+ /// Replaces the wrapped value with a new one, returning the old value.
327
327
///
328
328
/// # Panics
329
329
///
@@ -410,10 +410,12 @@ impl<T: PyClass + fmt::Debug> fmt::Debug for PyCell<T> {
410
410
/// Wraps a borrowed reference to a value in a `PyCell<T>`.
411
411
///
412
412
/// See the [`PyCell`](struct.PyCell.html) documentation for more.
413
+ ///
413
414
/// # Examples
414
- /// You can use `PyRef` as an alternative of `&self` receiver when
415
- /// - You need to access the pointer of `PyCell`.
416
- /// - You want to get super class.
415
+ ///
416
+ /// You can use `PyRef` as an alternative to a `&self` receiver when
417
+ /// - you need to access the pointer of the `PyCell`, or
418
+ /// - you want to get a super class.
417
419
/// ```
418
420
/// # use pyo3::prelude::*;
419
421
/// #[pyclass(subclass)]
@@ -449,8 +451,8 @@ pub struct PyRef<'p, T: PyClass> {
449
451
}
450
452
451
453
impl < ' p , T : PyClass > PyRef < ' p , T > {
452
- /// Returns `Python` token.
453
- /// This function is safe since PyRef has the same lifetime as a `GILGuard`.
454
+ /// Returns a `Python` token.
455
+ /// This function is safe since ` PyRef` has the same lifetime as a `GILGuard`.
454
456
pub fn py ( & self ) -> Python {
455
457
unsafe { Python :: assume_gil_acquired ( ) }
456
458
}
@@ -471,8 +473,13 @@ where
471
473
T : PyClass < BaseType = U > ,
472
474
U : PyClass ,
473
475
{
474
- /// Get `PyRef<T::BaseType>`.
475
- /// You can use this method to get super class of super class.
476
+ /// Gets a `PyRef<T::BaseType>`.
477
+ ///
478
+ /// While `as_ref()` returns a reference of type `&T::BaseType`, this cannot be
479
+ /// used to get the base of `T::BaseType`.
480
+ ///
481
+ /// But with the help of this method, you can get hold of instances of the
482
+ /// super-superclass when needed.
476
483
///
477
484
/// # Examples
478
485
/// ```
@@ -560,14 +567,14 @@ impl<T: PyClass + fmt::Debug> fmt::Debug for PyRef<'_, T> {
560
567
561
568
/// Wraps a mutable borrowed reference to a value in a `PyCell<T>`.
562
569
///
563
- /// See the [`PyCell`](struct.PyCell.html) and [`PyRef`](struct.PyRef.html) documentations for more.
570
+ /// See the [`PyCell`](struct.PyCell.html) and [`PyRef`](struct.PyRef.html) documentation for more.
564
571
pub struct PyRefMut < ' p , T : PyClass > {
565
572
inner : & ' p PyCell < T > ,
566
573
}
567
574
568
575
impl < ' p , T : PyClass > PyRefMut < ' p , T > {
569
- /// Returns `Python` token.
570
- /// This function is safe since PyRefMut has the same lifetime as a `GILGuard`.
576
+ /// Returns a `Python` token.
577
+ /// This function is safe since ` PyRefMut` has the same lifetime as a `GILGuard`.
571
578
pub fn py ( & self ) -> Python {
572
579
unsafe { Python :: assume_gil_acquired ( ) }
573
580
}
@@ -598,8 +605,8 @@ where
598
605
T : PyClass < BaseType = U > ,
599
606
U : PyClass ,
600
607
{
601
- /// Get `PyRef<T::BaseType>`.
602
- /// See [`PyRef::into_super`](struct.PyRef.html#method.into_super) for more.
608
+ /// Gets a `PyRef<T::BaseType>`.
609
+ /// See [`PyRef::into_super`](struct.PyRef.html#method.into_super) for more.
603
610
pub fn into_super ( self ) -> PyRefMut < ' p , U > {
604
611
let PyRefMut { inner } = self ;
605
612
std:: mem:: forget ( self ) ;
@@ -673,7 +680,7 @@ impl BorrowFlag {
673
680
674
681
/// An error returned by [`PyCell::try_borrow`](struct.PyCell.html#method.try_borrow).
675
682
///
676
- /// In Python, you can catch this error by `except RuntimeError`.
683
+ /// In Python, you can catch this error using `except RuntimeError`.
677
684
pub struct PyBorrowError {
678
685
_private : ( ) ,
679
686
}
@@ -698,7 +705,7 @@ impl From<PyBorrowError> for PyErr {
698
705
699
706
/// An error returned by [`PyCell::try_borrow_mut`](struct.PyCell.html#method.try_borrow_mut).
700
707
///
701
- /// In Python, you can catch this error by `except RuntimeError`.
708
+ /// In Python, you can catch this error using `except RuntimeError`.
702
709
pub struct PyBorrowMutError {
703
710
_private : ( ) ,
704
711
}
0 commit comments