Make `downcast()` methods inline
This commit is contained in:
parent
8ca41be87b
commit
21fd1a91d0
|
@ -995,6 +995,7 @@ impl PyObject {
|
||||||
///
|
///
|
||||||
/// This can cast only to native Python types, not types implemented in Rust. For a more
|
/// This can cast only to native Python types, not types implemented in Rust. For a more
|
||||||
/// flexible alternative, see [`Py::extract`](struct.Py.html#method.extract).
|
/// flexible alternative, see [`Py::extract`](struct.Py.html#method.extract).
|
||||||
|
#[inline]
|
||||||
pub fn downcast<'p, T>(&'p self, py: Python<'p>) -> Result<&T, PyDowncastError<'_>>
|
pub fn downcast<'p, T>(&'p self, py: Python<'p>) -> Result<&T, PyDowncastError<'_>>
|
||||||
where
|
where
|
||||||
T: PyTryFrom<'p>,
|
T: PyTryFrom<'p>,
|
||||||
|
@ -1010,6 +1011,7 @@ impl PyObject {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// Callers must ensure that the type is valid or risk type confusion.
|
/// Callers must ensure that the type is valid or risk type confusion.
|
||||||
|
#[inline]
|
||||||
pub unsafe fn downcast_unchecked<'p, T>(&'p self, py: Python<'p>) -> &T
|
pub unsafe fn downcast_unchecked<'p, T>(&'p self, py: Python<'p>) -> &T
|
||||||
where
|
where
|
||||||
T: PyTryFrom<'p>,
|
T: PyTryFrom<'p>,
|
||||||
|
|
|
@ -773,6 +773,7 @@ impl PyAny {
|
||||||
/// assert!(any.downcast::<PyList>().is_err());
|
/// assert!(any.downcast::<PyList>().is_err());
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
pub fn downcast<'p, T>(&'p self) -> Result<&'p T, PyDowncastError<'_>>
|
pub fn downcast<'p, T>(&'p self) -> Result<&'p T, PyDowncastError<'_>>
|
||||||
where
|
where
|
||||||
T: PyTryFrom<'p>,
|
T: PyTryFrom<'p>,
|
||||||
|
@ -785,6 +786,7 @@ impl PyAny {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// Callers must ensure that the type is valid or risk type confusion.
|
/// Callers must ensure that the type is valid or risk type confusion.
|
||||||
|
#[inline]
|
||||||
pub unsafe fn downcast_unchecked<'p, T>(&'p self) -> &'p T
|
pub unsafe fn downcast_unchecked<'p, T>(&'p self) -> &'p T
|
||||||
where
|
where
|
||||||
T: PyTryFrom<'p>,
|
T: PyTryFrom<'p>,
|
||||||
|
|
Loading…
Reference in New Issue