Struct cramjam::io::RustyBuffer[][src]

pub struct RustyBuffer { /* fields omitted */ }
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

impl RustyBuffer[src]

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'

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

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

pub fn len(&self) -> usize[src]

Length of the underlying buffer

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

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

pub fn read<'a>(
    &mut self,
    py: Python<'a>,
    n_bytes: Option<usize>
) -> PyResult<&'a PyBytes>
[src]

Read from the buffer in its current position, returns bytes; optionally specify number of bytes to read.

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

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

pub fn seek(
    &mut self,
    position: isize,
    whence: Option<usize>
) -> PyResult<usize>
[src]

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

pub fn seekable(&self) -> bool[src]

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

pub fn tell(&self) -> usize[src]

Give the current position of the buffer.

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

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.

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

Truncate the buffer

Trait Implementations

impl Default for RustyBuffer[src]

fn default() -> RustyBuffer

Notable traits for RustyBuffer

impl Read for RustyBufferimpl Write for RustyBuffer
[src]

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

impl<'a> ExtractExt<'a> for &'a RustyBuffer[src]

impl<'a> ExtractExt<'a> for &'a mut RustyBuffer[src]

impl From<Vec<u8, Global>> for RustyBuffer[src]

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

Performs the conversion.

impl HasMethodsInventory for RustyBuffer[src]

type Methods = Pyo3MethodsInventoryForRustyBuffer

impl IntoPy<Py<PyAny>> for RustyBuffer[src]

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

Performs the conversion.

impl<'p> PyBufferGetBufferProtocol<'p> for RustyBuffer[src]

impl<'p> PyBufferProtocol<'p> for RustyBuffer[src]

fn bf_getbuffer(
    slf: PyRefMut<'_, Self>,
    view: *mut Py_buffer,
    flags: c_int
) -> <RustyBuffer as PyBufferGetBufferProtocol<'p>>::Result

Notable traits for RustyBuffer

impl Read for RustyBufferimpl Write for RustyBuffer
[src]

fn bf_releasebuffer(
    _slf: PyRefMut<'_, Self>,
    _view: *mut Py_buffer
) -> <RustyBuffer as PyBufferReleaseBufferProtocol<'p>>::Result

Notable traits for RustyBuffer

impl Read for RustyBufferimpl Write for RustyBuffer
[src]

impl<'p> PyBufferReleaseBufferProtocol<'p> for RustyBuffer[src]

type Result = ()

impl PyClass for RustyBuffer[src]

type Dict = PyClassDummySlot

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

type WeakRef = PyClassDummySlot

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

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict. Read more

impl PyClassAlloc for RustyBuffer[src]

unsafe fn new(py: Python<'_>, subtype: *mut PyTypeObject) -> *mut Self::Layout[src]

Allocate the actual field for #[pyclass]. Read more

unsafe fn dealloc(py: Python<'_>, self_: *mut Self::Layout)[src]

Deallocate #[pyclass] on the Python heap. Read more

impl PyClassSend for RustyBuffer[src]

type ThreadChecker = ThreadCheckerStub<RustyBuffer>

impl<'p> PyObjectBoolProtocol<'p> for RustyBuffer[src]

type Result = bool

impl<'p> PyObjectProtocol<'p> for RustyBuffer[src]

fn __repr__(&'p self) -> <RustyBuffer as PyObjectReprProtocol<'p>>::Result

Notable traits for RustyBuffer

impl Read for RustyBufferimpl Write for RustyBuffer
[src]

fn __bool__(&'p self) -> <RustyBuffer as PyObjectBoolProtocol<'p>>::Result

Notable traits for RustyBuffer

impl Read for RustyBufferimpl Write for RustyBuffer
[src]

fn __getattr__(&'p self, name: Self::Name) -> Self::Result where
    Self: PyObjectGetAttrProtocol<'p>, 
[src]

fn __setattr__(
    &'p mut self,
    name: Self::Name,
    value: Self::Value
) -> Self::Result where
    Self: PyObjectSetAttrProtocol<'p>, 
[src]

fn __delattr__(&'p mut self, name: Self::Name) -> Self::Result where
    Self: PyObjectDelAttrProtocol<'p>, 
[src]

fn __str__(&'p self) -> Self::Result where
    Self: PyObjectStrProtocol<'p>, 
[src]

fn __format__(&'p self, format_spec: Self::Format) -> Self::Result where
    Self: PyObjectFormatProtocol<'p>, 
[src]

fn __hash__(&'p self) -> Self::Result where
    Self: PyObjectHashProtocol<'p>, 
[src]

fn __bytes__(&'p self) -> Self::Result where
    Self: PyObjectBytesProtocol<'p>, 
[src]

fn __richcmp__(&'p self, other: Self::Other, op: CompareOp) -> Self::Result where
    Self: PyObjectRichcmpProtocol<'p>, 
[src]

impl<'p> PyObjectReprProtocol<'p> for RustyBuffer[src]

type Result = String

impl PyProtoMethods for RustyBuffer[src]

fn for_each_proto_slot<Visitor: FnMut(PyType_Slot)>(visitor: Visitor)[src]

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

impl<'p> PySequenceContainsProtocol<'p> for RustyBuffer[src]

type Item = u8

type Result = bool

impl<'p> PySequenceLenProtocol<'p> for RustyBuffer[src]

type Result = usize

impl<'p> PySequenceProtocol<'p> for RustyBuffer[src]

fn __len__(&'p self) -> <RustyBuffer as PySequenceLenProtocol<'p>>::Result

Notable traits for RustyBuffer

impl Read for RustyBufferimpl Write for RustyBuffer
[src]

fn __contains__(
    &'p self,
    x: <RustyBuffer as PySequenceContainsProtocol<'p>>::Item
) -> <RustyBuffer as PySequenceContainsProtocol<'p>>::Result

Notable traits for RustyBuffer

impl Read for RustyBufferimpl Write for RustyBuffer
[src]

fn __getitem__(&'p self, idx: Self::Index) -> Self::Result where
    Self: PySequenceGetItemProtocol<'p>, 
[src]

fn __setitem__(
    &'p mut self,
    idx: Self::Index,
    value: Self::Value
) -> Self::Result where
    Self: PySequenceSetItemProtocol<'p>, 
[src]

fn __delitem__(&'p mut self, idx: Self::Index) -> Self::Result where
    Self: PySequenceDelItemProtocol<'p>, 
[src]

fn __concat__(&'p self, other: Self::Other) -> Self::Result where
    Self: PySequenceConcatProtocol<'p>, 
[src]

fn __repeat__(&'p self, count: Self::Index) -> Self::Result where
    Self: PySequenceRepeatProtocol<'p>, 
[src]

fn __inplace_concat__(&'p mut self, other: Self::Other) -> Self::Result where
    Self: PySequenceInplaceConcatProtocol<'p>, 
[src]

fn __inplace_repeat__(&'p mut self, count: Self::Index) -> Self::Result where
    Self: PySequenceInplaceRepeatProtocol<'p>, 
[src]

impl PyTypeInfo for RustyBuffer[src]

type Type = RustyBuffer

Type of objects to store in PyObject struct

type BaseType = PyAny

Base class

type Layout = PyCell<Self>

Layout

type BaseLayout = PyCellBase<PyAny>

Layout of Basetype.

type Initializer = PyClassInitializer<Self>

Initializer for layout

type AsRefTarget = PyCell<Self>

Utility type to make Py::as_ref work

const NAME: &'static str[src]

Class name

const MODULE: Option<&'static str>[src]

Module name, if any

const DESCRIPTION: &'static str[src]

Class doc string

const FLAGS: usize[src]

Type flags (ie PY_TYPE_FLAG_GC, PY_TYPE_FLAG_WEAKREF)

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

PyTypeObject instance for this type.

fn is_type_of(object: &PyAny) -> bool[src]

Checks if object is an instance of this type or a subclass of this type.

fn is_exact_type_of(object: &PyAny) -> bool[src]

Checks if object is an instance of this type.

impl Read for RustyBuffer[src]

fn read(&mut self, buf: &mut [u8]) -> Result<usize>[src]

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>1.36.0[src]

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

fn is_read_vectored(&self) -> bool[src]

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

unsafe fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>1.0.0[src]

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>1.0.0[src]

Read all bytes until EOF in this source, appending them to buf. Read more

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

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

fn by_ref(&mut self) -> &mut Self1.0.0[src]

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

fn bytes(self) -> Bytes<Self>1.0.0[src]

Transforms this Read instance to an Iterator over its bytes. Read more

fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0[src]

Creates an adaptor which will chain this stream with another. Read more

fn take(self, limit: u64) -> Take<Self>1.0.0[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl Seek for RustyBuffer[src]

fn seek(&mut self, pos: SeekFrom) -> Result<u64>[src]

Seek to an offset, in bytes, in a stream. Read more

fn rewind(&mut self) -> Result<(), Error>[src]

🔬 This is a nightly-only experimental API. (seek_rewind)

Rewind to the beginning of a stream. Read more

fn stream_len(&mut self) -> Result<u64, Error>[src]

🔬 This is a nightly-only experimental API. (seek_stream_len)

Returns the length of this stream (in bytes). Read more

fn stream_position(&mut self) -> Result<u64, Error>1.51.0[src]

Returns the current seek position from the start of the stream. Read more

impl Write for RustyBuffer[src]

fn write(&mut self, buf: &[u8]) -> Result<usize>[src]

Write a buffer into this writer, returning how many bytes were written. Read more

fn flush(&mut self) -> Result<()>[src]

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

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

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

fn is_write_vectored(&self) -> bool[src]

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Writer has an efficient write_vectored implementation. Read more

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

Attempts to write an entire buffer into this writer. Read more

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

🔬 This is a nightly-only experimental API. (write_all_vectored)

Attempts to write multiple buffers into this writer. Read more

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

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self1.0.0[src]

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

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> PyErrArguments for T where
    T: IntoPy<Py<PyAny>> + Send + Sync
[src]

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

Arguments for exception

impl<T> PyTypeObject for T where
    T: PyTypeInfo
[src]

pub fn type_object(py: Python<'_>) -> &PyType[src]

Returns the safe abstraction over the type object.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.