pub struct PyBytes(/* private fields */);
Expand description
A wrapper around a bytes::Bytes
.
This implements both import and export via the Python buffer protocol.
§Buffer protocol import
This can be very useful as a general way to support ingest of a Python buffer protocol object.
The underlying Bytes manages the external memory, automatically calling the Python buffer’s release callback when the internal reference count reaches 0.
Note that converting this Bytes
into a BytesMut will always create a
deep copy of the buffer into newly allocated memory, since this Bytes
is constructed from an
owner.
§Buffer protocol export
PyBytes implements the Python buffer protocol to enable Python to access the underlying Bytes
data view without copies. In Python, this PyBytes
object can be passed to Python bytes
or
memoryview
constructors, numpy.frombuffer
, or any other function that supports buffer
protocol input.
Implementations§
Trait Implementations§
Source§impl Debug for PyBytes
This is mostly the same as the upstream bytes::Bytes
Debug
impl,
however we don’t use it because that impl doesn’t look how the python bytes repr looks; this
isn’t exactly the same either, as the python repr will switch between '
and "
based on the
presence of the other in the string, but it’s close enough AND we don’t have to do a full scan
of the bytes to check for that.
impl Debug for PyBytes
This is mostly the same as the upstream bytes::Bytes
Debug
impl,
however we don’t use it because that impl doesn’t look how the python bytes repr looks; this
isn’t exactly the same either, as the python repr will switch between '
and "
based on the
presence of the other in the string, but it’s close enough AND we don’t have to do a full scan
of the bytes to check for that.
Source§impl<'py> FromPyObject<'py> for PyBytes
impl<'py> FromPyObject<'py> for PyBytes
Source§impl<'py> IntoPyObject<'py> for PyBytes
impl<'py> IntoPyObject<'py> for PyBytes
Source§type Output = Bound<'py, <PyBytes as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <PyBytes as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl Ord for PyBytes
impl Ord for PyBytes
Source§impl PartialOrd for PyBytes
impl PartialOrd for PyBytes
Source§impl PyClassBaseType for PyBytes
impl PyClassBaseType for PyBytes
type LayoutAsBase = PyClassObject<PyBytes>
type BaseNativeType = <PyBytes as PyClassImpl>::BaseNativeType
type Initializer = PyClassInitializer<PyBytes>
type PyClassMutability = <PyBytes as PyClassImpl>::PyClassMutability
Source§impl PyClassImpl for PyBytes
impl PyClassImpl for PyBytes
Source§const IS_BASETYPE: bool = true
const IS_BASETYPE: bool = true
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = true
const IS_SEQUENCE: bool = true
Source§type ThreadChecker = SendablePyClass<PyBytes>
type ThreadChecker = SendablePyClass<PyBytes>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::ImmutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn weaklist_offset() -> Option<Py_ssize_t>
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
Source§impl PyClassNewTextSignature<PyBytes> for PyClassImplCollector<PyBytes>
impl PyClassNewTextSignature<PyBytes> for PyClassImplCollector<PyBytes>
fn new_text_signature(self) -> Option<&'static str>
Source§impl PyMethods<PyBytes> for PyClassImplCollector<PyBytes>
impl PyMethods<PyBytes> for PyClassImplCollector<PyBytes>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for PyBytes
impl PyTypeInfo for PyBytes
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
Source§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
PyTypeInfo::type_object
PyTypeInfo::type_object
.Source§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type or a subclass of this type.Source§fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_type_of
PyTypeInfo::is_type_of
.Source§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type.Source§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_exact_type_of
PyTypeInfo::is_exact_type_of
.impl DerefToPyAny for PyBytes
impl Eq for PyBytes
impl StructuralPartialEq for PyBytes
Auto Trait Implementations§
impl !Freeze for PyBytes
impl RefUnwindSafe for PyBytes
impl Send for PyBytes
impl Sync for PyBytes
impl Unpin for PyBytes
impl UnwindSafe for PyBytes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
Source§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self
into an owned Python object, dropping type information.