Struct RustyBuffer

Source
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

§Example
from cramjam import Buffer
buf = Buffer(b'start bytes')
buf.read(5)
b'start'
Source

pub fn __init__(data: Option<BytesType<'_>>) -> PyResult<Self>

Instantiate the object, optionally with any supported bytes-like object in BytesType

Source

pub fn len(&self) -> usize

Length of the underlying buffer

Source

pub fn write(&mut self, input: BytesType<'_>) -> PyResult<usize>

Write some bytes to the buffer, where input data can be anything in BytesType

Source

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.

Source

pub fn readinto(&mut self, output: BytesType<'_>) -> PyResult<usize>

Read from the buffer in its current position, into a BytesType object.

Source

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
Source

pub fn seekable(&self) -> bool

Whether the buffer is seekable; here just for compatibility, it always returns True.

Source

pub fn tell(&self) -> usize

Give the current position of the buffer.

Source

pub fn set_len(&mut self, size: usize) -> PyResult<()>

Set the length of the buffer. If less than current length, it will truncate to the size given; otherwise will be null byte filled to the size.

Source

pub fn truncate(&mut self) -> PyResult<()>

Truncate the buffer

Trait Implementations§

Source§

impl Default for RustyBuffer

Source§

fn default() -> RustyBuffer

Returns the “default value” for a type. Read more
Source§

impl From<Vec<u8>> for RustyBuffer

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl IntoPy<Py<PyAny>> for RustyBuffer

Source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
Source§

impl<'p> PyBufferGetBufferProtocol<'p> for RustyBuffer

Source§

impl<'p> PyBufferProtocol<'p> for RustyBuffer

Source§

impl PyBufferProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>

Source§

impl<'p> PyBufferReleaseBufferProtocol<'p> for RustyBuffer

Source§

impl PyClass for RustyBuffer

Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

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>

Source§

impl PyClassImpl for RustyBuffer

Source§

const DOC: &'static str = /// A native Rust file-like object. Reading and writing takes place

Class doc string
Source§

const IS_GC: bool = false

#[pyclass(gc)]
Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

type Layout = PyCell<RustyBuffer>

Layout
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = ThreadCheckerStub<RustyBuffer>

This handles following two situations: Read more
Source§

fn for_each_method_def(visitor: &mut dyn FnMut(&[PyMethodDefType]))

Source§

fn get_new() -> Option<newfunc>

Source§

fn get_alloc() -> Option<allocfunc>

Source§

fn get_free() -> Option<freefunc>

Source§

fn get_call() -> Option<PyCFunctionWithKeywords>

Source§

fn for_each_proto_slot(visitor: &mut dyn FnMut(&[PyType_Slot]))

Source§

fn get_buffer() -> Option<&'static PyBufferProcs>

Source§

impl PyClassNewImpl<RustyBuffer> for PyClassImplCollector<RustyBuffer>

Source§

impl PyMethods<RustyBuffer> for PyClassImplCollector<RustyBuffer>

Source§

fn py_methods(self) -> &'static [PyMethodDefType]

Source§

impl<'p> PyObjectBoolProtocol<'p> for RustyBuffer

Source§

impl<'p> PyObjectProtocol<'p> for RustyBuffer

Source§

impl PyObjectProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>

Source§

impl<'p> PyObjectReprProtocol<'p> for RustyBuffer

Source§

impl<'p> PySequenceContainsProtocol<'p> for RustyBuffer

Source§

impl<'p> PySequenceLenProtocol<'p> for RustyBuffer

Source§

impl<'p> PySequenceProtocol<'p> for RustyBuffer

Source§

impl PySequenceProtocolSlots<RustyBuffer> for PyClassImplCollector<RustyBuffer>

Source§

impl PyTypeInfo for RustyBuffer

Source§

const NAME: &'static str = "Buffer"

Class name.
Source§

const MODULE: Option<&'static str> = ::std::option::Option::None

Module name, if any.
Source§

type AsRefTarget = PyCell<RustyBuffer>

Utility type to make Py::as_ref work.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

PyTypeObject instance for this type.
Source§

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

Checks if object is an instance of this type.
Source§

impl Read for RustyBuffer

Source§

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>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

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 more
1.0.0 · Source§

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 more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

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>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl Seek for RustyBuffer

Source§

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>

Rewind to the beginning of a stream. Read more
Source§

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
1.51.0 · Source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more
Source§

impl Write for RustyBuffer

Source§

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<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

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>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> PyTypeObject for T
where T: PyTypeInfo,

Source§

fn type_object(py: Python<'_>) -> &PyType

Returns the safe abstraction over the type object.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.