Make `downcast()` methods inline

This commit is contained in:
Georg Brandl 2022-11-19 09:08:51 +01:00
parent 8ca41be87b
commit 21fd1a91d0
2 changed files with 4 additions and 0 deletions

View File

@ -995,6 +995,7 @@ impl PyObject {
///
/// 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).
#[inline]
pub fn downcast<'p, T>(&'p self, py: Python<'p>) -> Result<&T, PyDowncastError<'_>>
where
T: PyTryFrom<'p>,
@ -1010,6 +1011,7 @@ impl PyObject {
/// # Safety
///
/// 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
where
T: PyTryFrom<'p>,

View File

@ -773,6 +773,7 @@ impl PyAny {
/// assert!(any.downcast::<PyList>().is_err());
/// });
/// ```
#[inline]
pub fn downcast<'p, T>(&'p self) -> Result<&'p T, PyDowncastError<'_>>
where
T: PyTryFrom<'p>,
@ -785,6 +786,7 @@ impl PyAny {
/// # Safety
///
/// Callers must ensure that the type is valid or risk type confusion.
#[inline]
pub unsafe fn downcast_unchecked<'p, T>(&'p self) -> &'p T
where
T: PyTryFrom<'p>,