Struct io::Writer

source ·
pub struct Writer<W>(/* private fields */);
Expand description

A stateful writer that keeps track of its current offset within the internal stateless ByteWriter I/O stream.

This implements the [core2::io::Write] trait for write-only access, as well as the [core2::io::Seek] trait if the underlying I/O stream implements KnownLength. It also forwards all other write-only I/O-related traits implemented by the underlying I/O stream.

Note: this is implemented as a thin wrapper around ReaderWriter.

Implementations§

source§

impl<W: ByteWriter> Writer<W>

source

pub fn new(writer: W) -> Self

Creates a new Writer with an initial offset of 0.

Trait Implementations§

source§

impl<IO> BlockIo for Writer<IO>where IO: BlockIo,

source§

fn block_size(&self) -> usize

Returns the size in bytes of a single block (i.e., sector), the minimum granularity of I/O transfers.
source§

impl<IO> BlockWriter for Writer<IO>where IO: BlockWriter,

source§

fn write_blocks( &mut self, buffer: &[u8], block_offset: usize ) -> Result<usize, IoError>

Writes blocks of data from the given buffer to this writer. Read more
source§

fn flush(&mut self) -> Result<(), IoError>

Flushes this entire writer’s output stream, ensuring all contents in intermediate buffers are fully written out.
source§

impl<IO> ByteWriter for Writer<IO>where IO: ByteWriter,

source§

fn write_at(&mut self, buffer: &[u8], offset: usize) -> Result<usize, IoError>

Writes bytes of data from the given buffer to this writer. Read more
source§

fn flush(&mut self) -> Result<(), IoError>

Flushes this writer’s output stream, ensuring all contents in intermediate buffers are fully written out.
source§

impl<IO> KnownLength for Writer<IO>where IO: KnownLength,

source§

fn len(&self) -> usize

Returns the length (size in bytes) of this I/O stream or device.
source§

impl<IO> Seek for Writer<IO>where IO: KnownLength,

source§

fn seek(&mut self, position: SeekFrom) -> Result<u64>

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

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

Rewind to the beginning of a stream. Read more
§

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

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

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

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

impl<IO> Write for Writer<IO>where IO: ByteWriter,

source§

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

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

fn flush(&mut self) -> Result<()>

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

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

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

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 Selfwhere Self: Sized,

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

Auto Trait Implementations§

§

impl<W> RefUnwindSafe for Writer<W>where W: RefUnwindSafe,

§

impl<W> Send for Writer<W>where W: Send,

§

impl<W> Sync for Writer<W>where W: Sync,

§

impl<W> Unpin for Writer<W>where W: Unpin,

§

impl<W> UnwindSafe for Writer<W>where W: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.