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§

Construct a new instance of TextWriter wrapping inner, which can be anything that implements Write.

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.

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.

Construct a new instance of TextWriter wrapping inner, which can be anything that implements WriteStr + WriteLayered, such as a Utf8Writer.

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.

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.

Flush and close the underlying stream and return the underlying stream object.

Return the underlying stream object.

Trait Implementations§

Borrows the file descriptor. Read more
Extracts the raw file descriptor. Read more
Close the resource and abandon any pending buffered contents or errors.
A suggested size, in bytes, for buffering for performance.
Formats the value using the given formatter. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Attempts to write an entire buffer into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more
Flush any buffers and declare the end of the stream. Subsequent writes will fail. Read more
Like Write::flush, but has a status parameter describing the future of the stream: Read more
Like Write::write_all, but takes a &str, allowing implementors which require valid UTF-8 to avoid re-validating the data. Read more
Like WriteStr::write_str but writes from a TextSubstr.
Like WriteStr::write_str but writes from a TextStr.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Borrows the reference. Read more
Return a borrowing view of a resource which dereferences to a &Target. Read more
Extracts the grip.
Returns the raw value.
Extracts the raw grip.
Returns the raw value.
Borrows the reference.
Return a borrowing view of a resource which dereferences to a &Target. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.