pub struct PyFileLikeObject { /* private fields */ }
Expand description
A wrapper around a Python object that implements the file-like interface.
Implementations§
Source§impl PyFileLikeObject
Wraps a PyObject
, and implements read, seek, and write for it.
impl PyFileLikeObject
Wraps a PyObject
, and implements read, seek, and write for it.
Sourcepub fn new(object: PyObject) -> PyResult<Self>
pub fn new(object: PyObject) -> PyResult<Self>
Creates an instance of a PyFileLikeObject
from a PyObject
.
To assert the object has the required methods methods,
instantiate it with with_requirements
.
Prefer using py_new
if you already have a Bound<PyAny>
object, as this
method re-acquires the GIL internally.
Sourcepub fn with_requirements(
object: PyObject,
read: bool,
write: bool,
seek: bool,
fileno: bool,
) -> PyResult<Self>
pub fn with_requirements( object: PyObject, read: bool, write: bool, seek: bool, fileno: bool, ) -> PyResult<Self>
Same as PyFileLikeObject::new
, but validates that the underlying
python object has a read
, write
, and seek
methods in respect to parameters.
Will return a TypeError
if object does not have read
, seek
, write
and fileno
methods.
Prefer using py_with_requirements
if you already have a
Bound<PyAny>
object, as this method re-acquires the GIL internally.
Sourcepub fn py_new(obj: Bound<'_, PyAny>) -> PyResult<Self>
pub fn py_new(obj: Bound<'_, PyAny>) -> PyResult<Self>
Creates an instance of a PyFileLikeObject
from a PyObject
.
Prefer using this instead of new
if you already have a Bound<PyAny>
object, as this method does not acquire the GIL internally.
Sourcepub fn py_with_requirements(
obj: Bound<'_, PyAny>,
read: bool,
write: bool,
seek: bool,
fileno: bool,
) -> PyResult<Self>
pub fn py_with_requirements( obj: Bound<'_, PyAny>, read: bool, write: bool, seek: bool, fileno: bool, ) -> PyResult<Self>
Creates an instance of a PyFileLikeObject
from a PyObject
.
Prefer using this instead of with_requirements
if you already
have a Bound<PyAny>
object, as this method does not acquire the GIL internally.
pub fn py_read(&self, py: Python<'_>, buf: &mut [u8]) -> Result<usize>
pub fn py_write(&self, py: Python<'_>, buf: &[u8]) -> Result<usize>
pub fn py_flush(&self, py: Python<'_>) -> Result<()>
pub fn py_seek(&self, py: Python<'_>, pos: SeekFrom) -> Result<u64>
pub fn py_as_raw_fd(&self, py: Python<'_>) -> RawFd
pub fn py_clone(&self, py: Python<'_>) -> PyFileLikeObject ⓘ
Trait Implementations§
Source§impl AsRawFd for &PyFileLikeObject
impl AsRawFd for &PyFileLikeObject
Source§impl AsRawFd for PyFileLikeObject
impl AsRawFd for PyFileLikeObject
Source§impl Clone for PyFileLikeObject
impl Clone for PyFileLikeObject
Source§impl Debug for PyFileLikeObject
impl Debug for PyFileLikeObject
Source§impl<'py> FromPyObject<'py> for PyFileLikeObject
impl<'py> FromPyObject<'py> for PyFileLikeObject
Source§impl Read for &PyFileLikeObject
impl Read for &PyFileLikeObject
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
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>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
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>
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>
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>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl Read for PyFileLikeObject
impl Read for PyFileLikeObject
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
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>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
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>
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>
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>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl Seek for &PyFileLikeObject
impl Seek for &PyFileLikeObject
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)Source§impl Seek for PyFileLikeObject
impl Seek for PyFileLikeObject
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)Source§impl Write for &PyFileLikeObject
impl Write for &PyFileLikeObject
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)Source§impl Write for PyFileLikeObject
impl Write for PyFileLikeObject
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)