pub struct Writer<W: Write> { /* private fields */ }
Expand description
A fixed width data writer. It writes data provided in iterators to any type that implements io::Write.
§Example
Writing a Vec<String>
to a file:
use fixed_width;
use std::io::Write;
use fixed_width::Writer;
let data = vec![
"1234".to_string(),
"5678".to_string(),
];
let mut wrtr = Writer::from_memory();
wrtr.write_iter(data.iter());
wrtr.flush();
Implementations§
Source§impl<W> Writer<W>where
W: Write,
impl<W> Writer<W>where
W: Write,
Sourcepub fn from_writer(wrtr: W) -> Self
pub fn from_writer(wrtr: W) -> Self
Creates a new writer from any type that implements io::Write
Sourcepub fn from_buffer(buf: BufWriter<W>) -> Self
pub fn from_buffer(buf: BufWriter<W>) -> Self
Creates a new writer from a io::BufWriter that wraps a type that implements io::Write
Sourcepub fn write_serialized<T: FixedWidth + Serialize>(
&mut self,
records: impl Iterator<Item = T>,
) -> Result<()>
pub fn write_serialized<T: FixedWidth + Serialize>( &mut self, records: impl Iterator<Item = T>, ) -> Result<()>
Writes the given iterator of FixedWidth + Serialize
types to the underlying writer,
optionally inserting linebreaks if specified.
Sourcepub fn write_iter<T: AsByteSlice>(
&mut self,
records: impl Iterator<Item = T>,
) -> Result<()>
pub fn write_iter<T: AsByteSlice>( &mut self, records: impl Iterator<Item = T>, ) -> Result<()>
Writes the given iterator of types that implement AsByteSlice to the underlying writer, optionally inserting linebreaks if specified.
Sourcepub fn write_linebreak(&mut self) -> Result<()>
pub fn write_linebreak(&mut self) -> Result<()>
Writes the linebreak specified to the underlying writer. Does nothing if there is no linebreak.
Trait Implementations§
Source§impl<W> Write for Writer<W>where
W: Write,
impl<W> Write for Writer<W>where
W: Write,
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
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>
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
Auto Trait Implementations§
impl<W> Freeze for Writer<W>where
W: Freeze,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more