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§
source§impl<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.
source§impl<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§
source§impl<Inner: WriteStr + WriteLayered + AsFd> AsFd for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered + AsFd> AsFd for TextWriter<Inner>
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
source§impl<Inner: WriteStr + WriteLayered + AsRawFd> AsRawFd for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered + AsRawFd> AsRawFd for TextWriter<Inner>
source§impl<Inner: WriteStr + WriteLayered> Bufferable for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> Bufferable for TextWriter<Inner>
source§impl<Inner: Debug> Debug for TextWriter<Inner>
impl<Inner: Debug> Debug for TextWriter<Inner>
source§impl<Inner: WriteStr + WriteLayered> Write for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> Write for TextWriter<Inner>
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
write_all_vectored
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§impl<Inner: WriteStr + WriteLayered> WriteLayered for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> WriteLayered for TextWriter<Inner>
source§impl<Inner: WriteStr + WriteLayered> WriteStr for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> WriteStr for TextWriter<Inner>
source§impl<Inner: WriteStr + WriteLayered> WriteText for TextWriter<Inner>
impl<Inner: WriteStr + WriteLayered> WriteText for TextWriter<Inner>
source§fn write_text_substr(&mut self, s: &TextSubstr) -> Result<()>
fn write_text_substr(&mut self, s: &TextSubstr) -> Result<()>
WriteStr::write_str
but writes from a TextSubstr
.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§
§impl<T> AsFilelike for Twhere
T: AsFd,
impl<T> AsFilelike for Twhere T: AsFd,
§fn as_filelike(&self) -> BorrowedFd<'_>
fn as_filelike(&self) -> BorrowedFd<'_>
§fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where
Target: FilelikeViewType,
fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where Target: FilelikeViewType,
&Target
. Read moresource§impl<T> AsGrip for Twhere
T: AsFd,
impl<T> AsGrip for Twhere T: AsFd,
source§fn as_grip(&self) -> BorrowedFd<'_>
fn as_grip(&self) -> BorrowedFd<'_>
§impl<T> AsRawFilelike for Twhere
T: AsRawFd,
impl<T> AsRawFilelike for Twhere T: AsRawFd,
§fn as_raw_filelike(&self) -> i32
fn as_raw_filelike(&self) -> i32
source§impl<T> AsRawGrip for Twhere
T: AsRawFd,
impl<T> AsRawGrip for Twhere T: AsRawFd,
source§fn as_raw_grip(&self) -> i32
fn as_raw_grip(&self) -> i32
§impl<T> AsRawSocketlike for Twhere
T: AsRawFd,
impl<T> AsRawSocketlike for Twhere T: AsRawFd,
§fn as_raw_socketlike(&self) -> i32
fn as_raw_socketlike(&self) -> i32
§impl<T> AsSocketlike for Twhere
T: AsFd,
impl<T> AsSocketlike for Twhere T: AsFd,
§fn as_socketlike(&self) -> BorrowedFd<'_>
fn as_socketlike(&self) -> BorrowedFd<'_>
§fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where
Target: SocketlikeViewType,
fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where Target: SocketlikeViewType,
&Target
. Read more