Struct basic_text::TextWriter
source · [−]pub struct TextWriter<Inner> { /* private fields */ }Expand description
A WriteLayered implementation which translates to an output
WriteLayered producing a valid Basic Text stream from an arbitrary
byte sequence.
write is not guaranteed to perform a single operation, because short
writes could produce invalid UTF-8, so write will retry as needed.
Examples
use basic_text::TextWriter;
use layered_io::WriteLayered;
let mut output = TextWriter::new(std::io::stdout());
// write to `output`
output.close().unwrap();Implementations
sourceimpl<Inner: Write> TextWriter<Utf8Writer<LayeredWriter<Inner>>>
impl<Inner: Write> TextWriter<Utf8Writer<LayeredWriter<Inner>>>
sourcepub fn new(inner: Inner) -> Self
pub fn new(inner: Inner) -> Self
Construct a new instance of TextWriter wrapping inner, which can be
anything that implements Write.
sourcepub fn with_bom_compatibility(inner: Inner) -> Result<Self>
pub fn with_bom_compatibility(inner: Inner) -> Result<Self>
Like new, but writes a U+FEFF (BOM) to the beginning of the output
stream for compatibility with consumers that require that to determine
the text encoding.
sourcepub fn with_crlf_compatibility(inner: Inner) -> Self
pub fn with_crlf_compatibility(inner: Inner) -> Self
Like new, but enables CRLF output mode, which translates “\n” to
“\r\n” for compatibility with consumers that need that.
Note: This is not often needed; even on Windows these days most things are ok with plain ‘\n’ line endings, including Windows Notepad. The main notable things that really need them are IETF RFCs, for example RFC-5198.
sourceimpl<Inner: WriteStr + WriteLayered> TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> TextWriter<Inner>
sourcepub fn from_utf8(inner: Inner) -> Self
pub fn from_utf8(inner: Inner) -> Self
Construct a new instance of TextWriter wrapping inner, which
can be anything that implements WriteStr + WriteLayered, such as a
Utf8Writer.
sourcepub fn from_utf8_with_bom_compatibility(inner: Inner) -> Result<Self>
pub fn from_utf8_with_bom_compatibility(inner: Inner) -> Result<Self>
Like from_utf8, but writes a U+FEFF (BOM) to the beginning of the
output stream for compatibility with consumers that require that to
determine the text encoding.
sourcepub fn from_utf8_with_crlf_compatibility(inner: Inner) -> Self
pub fn from_utf8_with_crlf_compatibility(inner: Inner) -> Self
Like from_utf8, but enables CRLF output mode, which translates “\n”
to “\r\n” for compatibility with consumers that need that.
Note: This is not often needed; even on Windows these days most things are ok with plain ‘\n’ line endings, including Windows Notepad. The main notable things that really need them are IETF RFCs, for example RFC-5198.
sourcepub fn close_into_inner(self) -> Result<Inner>
pub fn close_into_inner(self) -> Result<Inner>
Flush and close the underlying stream and return the underlying stream object.
sourcepub fn abandon_into_inner(self) -> Inner
pub fn abandon_into_inner(self) -> Inner
Return the underlying stream object.
Trait Implementations
sourceimpl<Inner: WriteStr + WriteLayered + AsFd> AsFd for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered + AsFd> AsFd for TextWriter<Inner>
sourcefn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrows the file descriptor. Read more
sourceimpl<Inner: WriteStr + WriteLayered + AsRawFd> AsRawFd for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered + AsRawFd> AsRawFd for TextWriter<Inner>
sourceimpl<Inner: WriteStr + WriteLayered> Bufferable for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> Bufferable for TextWriter<Inner>
sourcefn suggested_buffer_size(&self) -> usize
fn suggested_buffer_size(&self) -> usize
A suggested size, in bytes, for buffering for performance.
sourceimpl<Inner: Debug> Debug for TextWriter<Inner>
impl<Inner: Debug> Debug for TextWriter<Inner>
sourceimpl<Inner: WriteStr + WriteLayered> Write for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> Write for TextWriter<Inner>
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)Determines if this Writer has an efficient write_vectored
implementation. Read more
sourcefn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
write_all_vectored)Attempts to write multiple buffers into this writer. Read more
1.0.0 · sourcefn 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
sourceimpl<Inner: WriteStr + WriteLayered> WriteLayered for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> WriteLayered for TextWriter<Inner>
sourceimpl<Inner: WriteStr + WriteLayered> WriteStr for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> WriteStr for TextWriter<Inner>
sourceimpl<Inner: WriteStr + WriteLayered> WriteText for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> WriteText for TextWriter<Inner>
sourcefn write_text_substr(&mut self, s: &TextSubstr) -> Result<()>
fn write_text_substr(&mut self, s: &TextSubstr) -> Result<()>
Like WriteStr::write_str but writes from a TextSubstr.
sourcefn write_text(&mut self, buf: &TextStr) -> Result<()>
fn write_text(&mut self, buf: &TextStr) -> Result<()>
Like WriteStr::write_str but writes from a TextStr.
Auto Trait Implementations
impl<Inner> RefUnwindSafe for TextWriter<Inner> where
Inner: RefUnwindSafe,
impl<Inner> Send for TextWriter<Inner> where
Inner: Send,
impl<Inner> Sync for TextWriter<Inner> where
Inner: Sync,
impl<Inner> Unpin for TextWriter<Inner> where
Inner: Unpin,
impl<Inner> UnwindSafe for TextWriter<Inner> where
Inner: UnwindSafe,
Blanket Implementations
sourceimpl<T> AsFilelike for T where
T: AsFd,
impl<T> AsFilelike for T where
T: AsFd,
sourcefn as_filelike(&self) -> BorrowedFd<'_>
fn as_filelike(&self) -> BorrowedFd<'_>
Borrows the reference. Read more
sourcefn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target> where
Target: FilelikeViewType,
fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target> where
Target: FilelikeViewType,
Return a borrowing view of a resource which dereferences to a &Target. Read more
sourceimpl<T> AsGrip for T where
T: AsFd,
impl<T> AsGrip for T where
T: AsFd,
sourcefn as_grip(&self) -> BorrowedFd<'_>
fn as_grip(&self) -> BorrowedFd<'_>
Extracts the grip.
sourceimpl<T> AsRawFilelike for T where
T: AsRawFd,
impl<T> AsRawFilelike for T where
T: AsRawFd,
sourcefn as_raw_filelike(&self) -> i32
fn as_raw_filelike(&self) -> i32
Returns the raw value.
sourceimpl<T> AsRawGrip for T where
T: AsRawFd,
impl<T> AsRawGrip for T where
T: AsRawFd,
sourcefn as_raw_grip(&self) -> i32
fn as_raw_grip(&self) -> i32
Extracts the raw grip.
sourceimpl<T> AsRawSocketlike for T where
T: AsRawFd,
impl<T> AsRawSocketlike for T where
T: AsRawFd,
sourcefn as_raw_socketlike(&self) -> i32
fn as_raw_socketlike(&self) -> i32
Returns the raw value.
sourceimpl<T> AsSocketlike for T where
T: AsFd,
impl<T> AsSocketlike for T where
T: AsFd,
sourcefn as_socketlike(&self) -> BorrowedFd<'_>
fn as_socketlike(&self) -> BorrowedFd<'_>
Borrows the reference.
sourcefn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target> where
Target: SocketlikeViewType,
fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target> where
Target: SocketlikeViewType,
Return a borrowing view of a resource which dereferences to a &Target. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more