Struct slice::IoSlice [−][src]
pub struct IoSlice<T> where
T: Seek, { /* fields omitted */ }
A slice, subset, or view into some object.
IoSlice
impls both std::io::Read
and std::io::Write
when the source implements them (and only one if the source
only implements one).
example usage.
use { std::fs::File, slice::IoSlice }; let source = File::open("/home/annie/data.png")?; let start = 10; let length = 1000; // create a slice into `home/annie/data.png`, consisting of bytes [10 .. 10 + 1000] // of that file. // // `slice` impls both `std::io::Read` and `std::io::Write` because `source` // does too. let slice = IoSlice::new(source, start, length); // use like any other `std::io::Read` or `std::io::Write`: // // slice.read_to_string(...)?; // slice.read_exact(...)?; // slice.write_all(...)?; // // writeln!(slice, "hello {}", name)?; //
Methods
impl<T> IoSlice<T> where
T: Seek,
[src]
impl<T> IoSlice<T> where
T: Seek,
pub fn new(source: T, begin: u64, length: u64) -> Result<IoSlice<T>, Error>
[src]
pub fn new(source: T, begin: u64, length: u64) -> Result<IoSlice<T>, Error>
create a new slice into a specific subset of source
.
pub fn len(&self) -> u64
[src]
pub fn len(&self) -> u64
returns the total length of this io slice.
pub fn pos(&self) -> u64
[src]
pub fn pos(&self) -> u64
returns the current position of this slice.
pub fn position(&self) -> u64
[src]
pub fn position(&self) -> u64
returns the current position of this slice.
Trait Implementations
impl<T: Debug> Debug for IoSlice<T> where
T: Seek,
[src]
impl<T: Debug> Debug for IoSlice<T> where
T: Seek,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T> Seek for IoSlice<T> where
T: Seek,
[src]
impl<T> Seek for IoSlice<T> where
T: Seek,
fn seek(&mut self, position: SeekFrom) -> Result<u64, Error>
[src]
fn seek(&mut self, position: SeekFrom) -> Result<u64, Error>
Seek to an offset, in bytes, in a stream. Read more
impl<T> Read for IoSlice<T> where
T: Read + Seek,
[src]
impl<T> Read for IoSlice<T> where
T: Read + Seek,
fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
[src]
fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
fn read_to_end(&mut self, buffer: &mut Vec<u8>) -> Result<usize, Error>
[src]
fn read_to_end(&mut self, buffer: &mut Vec<u8>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into buf
. Read more
unsafe fn initializer(&self) -> Initializer
[src]
unsafe fn initializer(&self) -> Initializer
read_initializer
)Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
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]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Read
. Read more
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn bytes(self) -> Bytes<Self>
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
fn chars(self) -> Chars<Self>
[src]
fn chars(self) -> Chars<Self>
: Use str::from_utf8 instead: https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples
🔬 This is a nightly-only experimental API. (io
)
the semantics of a partial read/write of where errors happen is currently unclear and may change
Transforms this Read
instance to an [Iterator
] over [char
]s. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
fn take(self, limit: u64) -> Take<Self>
Creates an adaptor which will read at most limit
bytes from it. Read more
impl<T> Write for IoSlice<T> where
T: Write + Seek,
[src]
impl<T> Write for IoSlice<T> where
T: Write + Seek,
fn write(&mut self, buffer: &[u8]) -> Result<usize, Error>
[src]
fn write(&mut self, buffer: &[u8]) -> Result<usize, Error>
Write a buffer into this object, returning how many bytes were written. Read more
fn write_all(&mut self, buffer: &[u8]) -> Result<(), Error>
[src]
fn write_all(&mut self, buffer: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this write. Read more
fn flush(&mut self) -> Result<(), Error>
[src]
fn flush(&mut self) -> Result<(), Error>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Write
. Read more
impl<T> Clone for IoSlice<T> where
T: Clone + Seek,
[src]
impl<T> Clone for IoSlice<T> where
T: Clone + Seek,
ⓘImportant traits for IoSlice<T>fn clone(&self) -> IoSlice<T>
[src]
fn clone(&self) -> IoSlice<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T> TryClone for IoSlice<T> where
T: TryClone + Seek,
[src]
impl<T> TryClone for IoSlice<T> where
T: TryClone + Seek,