Add TryFrom
impls for PyByteArray
and PyMemoryView
This commit is contained in:
parent
5b94241bd7
commit
d4ed66fff0
|
@ -241,6 +241,16 @@ impl PyByteArray {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'py> TryFrom<&'py PyAny> for &'py PyByteArray {
|
||||
type Error = crate::PyErr;
|
||||
|
||||
/// Creates a new Python `bytearray` object from another Python object that
|
||||
/// implements the buffer protocol.
|
||||
fn try_from(value: &'py PyAny) -> Result<Self, Self::Error> {
|
||||
PyByteArray::from(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::exceptions;
|
||||
|
|
|
@ -17,3 +17,13 @@ impl PyMemoryView {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'py> TryFrom<&'py PyAny> for &'py PyMemoryView {
|
||||
type Error = crate::PyErr;
|
||||
|
||||
/// Creates a new Python `memoryview` object from another Python object that
|
||||
/// implements the buffer protocol.
|
||||
fn try_from(value: &'py PyAny) -> Result<Self, Self::Error> {
|
||||
PyMemoryView::from(value)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue