pub struct RustyBuffer { /* private fields */ }
Expand description
A native Rust file-like object. Reading and writing takes place through the Rust implementation, allowing access to the underlying bytes in Python.
§Python Example
>>> from cramjam import Buffer
>>> buf = Buffer(b"bytes")
>>> buf.read()
b'bytes'
Implementations§
Source§impl RustyBuffer
A Buffer object, similar to cramjam.File only the bytes are held in-memory
impl RustyBuffer
A Buffer object, similar to cramjam.File only the bytes are held in-memory
§Example
from cramjam import Buffer
buf = Buffer(b'start bytes')
buf.read(5)
b'start'
Sourcepub fn __init__(data: Option<BytesType<'_>>) -> PyResult<Self>
pub fn __init__(data: Option<BytesType<'_>>) -> PyResult<Self>
Instantiate the object, optionally with any supported bytes-like object in BytesType
Sourcepub fn write(&mut self, input: BytesType<'_>) -> PyResult<usize>
pub fn write(&mut self, input: BytesType<'_>) -> PyResult<usize>
Write some bytes to the buffer, where input data can be anything in BytesType
Sourcepub fn read<'a>(
&mut self,
py: Python<'a>,
n_bytes: Option<usize>,
) -> PyResult<&'a PyBytes>
pub fn read<'a>( &mut self, py: Python<'a>, n_bytes: Option<usize>, ) -> PyResult<&'a PyBytes>
Read from the buffer in its current position, returns bytes; optionally specify number of bytes to read.
Sourcepub fn readinto(&mut self, output: BytesType<'_>) -> PyResult<usize>
pub fn readinto(&mut self, output: BytesType<'_>) -> PyResult<usize>
Read from the buffer in its current position, into a BytesType object.
Sourcepub fn seek(
&mut self,
position: isize,
whence: Option<usize>,
) -> PyResult<usize>
pub fn seek( &mut self, position: isize, whence: Option<usize>, ) -> PyResult<usize>
Seek to a position within the buffer. whence follows the same values as IOBase.seek where:
0: from start of the stream
1: from current stream position
2: from end of the stream
Sourcepub fn seekable(&self) -> bool
pub fn seekable(&self) -> bool
Whether the buffer is seekable; here just for compatibility, it always returns True.
Trait Implementations§
Source§impl Default for RustyBuffer
impl Default for RustyBuffer
Source§impl<'p> PyBufferGetBufferProtocol<'p> for RustyBuffer
impl<'p> PyBufferGetBufferProtocol<'p> for RustyBuffer
Source§impl<'p> PyBufferProtocol<'p> for RustyBuffer
impl<'p> PyBufferProtocol<'p> for RustyBuffer
fn bf_getbuffer( slf: PyRefMut<'_, Self>, view: *mut Py_buffer, flags: c_int, ) -> <RustyBuffer as PyBufferGetBufferProtocol<'p>>::Result ⓘ
fn bf_releasebuffer( _slf: PyRefMut<'_, Self>, _view: *mut Py_buffer, ) -> <RustyBuffer as PyBufferReleaseBufferProtocol<'p>>::Result ⓘ
Source§impl PyBufferProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>
impl PyBufferProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>
fn buffer_protocol_slots(self) -> &'static [PyType_Slot]
Source§impl<'p> PyBufferReleaseBufferProtocol<'p> for RustyBuffer
impl<'p> PyBufferReleaseBufferProtocol<'p> for RustyBuffer
Source§impl PyClass for RustyBuffer
impl PyClass for RustyBuffer
Source§type Dict = PyClassDummySlot
type Dict = PyClassDummySlot
Specify this class has
#[pyclass(dict)]
or not.Source§type WeakRef = PyClassDummySlot
type WeakRef = PyClassDummySlot
Specify this class has
#[pyclass(weakref)]
or not.Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
The closest native ancestor. This is
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.Source§impl PyClassDescriptors<RustyBuffer> for PyClassImplCollector<RustyBuffer>
impl PyClassDescriptors<RustyBuffer> for PyClassImplCollector<RustyBuffer>
fn py_class_descriptors(self) -> &'static [PyMethodDefType]
Source§impl PyClassImpl for RustyBuffer
impl PyClassImpl for RustyBuffer
Source§const DOC: &'static str = /// A native Rust file-like object. Reading and writing takes place
const DOC: &'static str = /// A native Rust file-like object. Reading and writing takes place
Class doc string
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
#[pyclass(subclass)]
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
#[pyclass(extends=…)]
Source§type Layout = PyCell<RustyBuffer>
type Layout = PyCell<RustyBuffer>
Layout
Source§type ThreadChecker = ThreadCheckerStub<RustyBuffer>
type ThreadChecker = ThreadCheckerStub<RustyBuffer>
This handles following two situations: Read more
fn for_each_method_def(visitor: &mut dyn FnMut(&[PyMethodDefType]))
fn get_new() -> Option<newfunc>
fn get_alloc() -> Option<allocfunc>
fn get_free() -> Option<freefunc>
fn get_call() -> Option<PyCFunctionWithKeywords>
fn for_each_proto_slot(visitor: &mut dyn FnMut(&[PyType_Slot]))
fn get_buffer() -> Option<&'static PyBufferProcs>
Source§impl PyClassNewImpl<RustyBuffer> for PyClassImplCollector<RustyBuffer>
impl PyClassNewImpl<RustyBuffer> for PyClassImplCollector<RustyBuffer>
Source§impl PyMethods<RustyBuffer> for PyClassImplCollector<RustyBuffer>
impl PyMethods<RustyBuffer> for PyClassImplCollector<RustyBuffer>
fn py_methods(self) -> &'static [PyMethodDefType]
Source§impl<'p> PyObjectBoolProtocol<'p> for RustyBuffer
impl<'p> PyObjectBoolProtocol<'p> for RustyBuffer
Source§impl<'p> PyObjectProtocol<'p> for RustyBuffer
impl<'p> PyObjectProtocol<'p> for RustyBuffer
fn __repr__(&'p self) -> <RustyBuffer as PyObjectReprProtocol<'p>>::Result ⓘ
fn __bool__(&'p self) -> <RustyBuffer as PyObjectBoolProtocol<'p>>::Result ⓘ
Source§impl PyObjectProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>
impl PyObjectProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>
fn object_protocol_slots(self) -> &'static [PyType_Slot]
Source§impl<'p> PyObjectReprProtocol<'p> for RustyBuffer
impl<'p> PyObjectReprProtocol<'p> for RustyBuffer
Source§impl<'p> PySequenceContainsProtocol<'p> for RustyBuffer
impl<'p> PySequenceContainsProtocol<'p> for RustyBuffer
Source§impl<'p> PySequenceLenProtocol<'p> for RustyBuffer
impl<'p> PySequenceLenProtocol<'p> for RustyBuffer
Source§impl<'p> PySequenceProtocol<'p> for RustyBuffer
impl<'p> PySequenceProtocol<'p> for RustyBuffer
fn __len__(&'p self) -> <RustyBuffer as PySequenceLenProtocol<'p>>::Result ⓘ
fn __contains__( &'p self, x: <RustyBuffer as PySequenceContainsProtocol<'p>>::Item, ) -> <RustyBuffer as PySequenceContainsProtocol<'p>>::Result ⓘ
Source§impl PySequenceProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>
impl PySequenceProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>
fn sequence_protocol_slots(self) -> &'static [PyType_Slot]
Source§impl PyTypeInfo for RustyBuffer
impl PyTypeInfo for RustyBuffer
Source§type AsRefTarget = PyCell<RustyBuffer>
type AsRefTarget = PyCell<RustyBuffer>
Utility type to make Py::as_ref work.
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
PyTypeObject instance for this type.
Source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
Checks if
object
is an instance of this type or a subclass of this type.Source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
Checks if
object
is an instance of this type.Source§impl Read for RustyBuffer
impl Read for RustyBuffer
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Reads all bytes until EOF in this source, placing them into
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until EOF in this source, appending them to
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Reads the exact number of bytes required to fill
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Pull some bytes from this source into the specified buffer. Read more
Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Reads the exact number of bytes required to fill
cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adaptor for this instance of
Read
. Read moreSource§impl Seek for RustyBuffer
impl Seek for RustyBuffer
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Rewind to the beginning of a stream. Read more
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
🔬This is a nightly-only experimental API. (
seek_stream_len
)Returns the length of this stream (in bytes). Read more
Source§impl Write for RustyBuffer
impl Write for RustyBuffer
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations§
impl Freeze for RustyBuffer
impl RefUnwindSafe for RustyBuffer
impl Send for RustyBuffer
impl Sync for RustyBuffer
impl Unpin for RustyBuffer
impl UnwindSafe for RustyBuffer
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
Mutably borrows from an owned value. Read more
Source§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
Source§impl<T> PyTypeObject for Twhere
T: PyTypeInfo,
impl<T> PyTypeObject for Twhere
T: PyTypeInfo,
Source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
Returns the safe abstraction over the type object.