pub struct OutputTextStream { /* private fields */ }
Expand description

An output stream for plain text output.

An OutputTextStream implements Write so it supports write, write_all, etc. and can be used anywhere a Write-implementing object is needed.

OutputTextStream is unbuffered (even when it is stdout), so wrapping it in a std::io::BufWriter or std::io::LineWriter is recommended for performance.

The primary way to construct an OutputTextStream is to use it as a type in a kommand argument or a clap_derive struct. Command-line arguments will then be automatically converted into output streams. Currently supported syntaxes include:

  • Names starting with file: are interpreted as local filesystem URLs providing paths to files to open.
  • “-” is interpreted as standard output.
  • “(…)” runs a command with a pipe to the child process’ stdin, on platforms whch support it.
  • Names which don’t parse as URLs are interpreted as plain local filesystem paths. To force a string to be interpreted as a plain local path, arrange for it to begin with ./ or /.

Programs using OutputTextStream as an argument should avoid using std::io::stdout, std::println, or anything else which uses standard output implicitly.

Implementations§

source§

impl OutputTextStream

source

pub fn write_pseudonym(&mut self, pseudonym: &Pseudonym) -> Result<()>

Write the given Pseudonym to the output stream.

source

pub fn pseudonym(&self) -> Pseudonym

Return a Pseudonym which encapsulates this stream’s name (typically its filesystem path or its URL). This allows it to be written to an OutputByteStream while otherwise remaining entirely opaque.

source

pub fn media_type(&self) -> &MediaType

If the output stream metadata implies a particular media type, also known as MIME type, return it. Otherwise default to “text/plain; charset=utf-8”.

Trait Implementations§

source§

impl Bufferable for OutputTextStream

source§

fn abandon(&mut self)

Close the resource and abandon any pending buffered contents or errors.
source§

fn suggested_buffer_size(&self) -> usize

A suggested size, in bytes, for buffering for performance.
source§

impl Debug for OutputTextStream

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for OutputTextStream

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Write for OutputTextStream

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
source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
source§

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

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

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
source§

impl WriteLayered for OutputTextStream

source§

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

Flush any buffers and declare the end of the stream. Subsequent writes will fail.
source§

fn flush_with_status(&mut self, status: Status) -> Result<(), Error>

Like Write::flush, but has a status parameter describing the future of the stream: Read more
source§

impl WriteStr for OutputTextStream

source§

fn write_str(&mut self, buf: &str) -> Result<()>

Like Write::write_all, but takes a &str, allowing implementors which require valid UTF-8 to avoid re-validating the data.
source§

impl WriteTerminal for OutputTextStream

source§

fn color_support(&self) -> TerminalColorSupport

Test whether this output stream supports color control codes.
source§

fn color_preference(&self) -> bool

Test whether the user has indicated a preference for color output by default. Respects the NO_COLOR environment variable where applicable.
source§

fn is_output_terminal(&self) -> bool

Test whether the output is connected to a terminal. Read more
source§

fn color_default(&self) -> bool

Test whether color should be used on this terminal by default. This includes both whether color is supported and whether the user has not indicated a preference otherwise.
source§

impl WriteText for OutputTextStream

source§

fn write_text(&mut self, buf: &TextStr) -> Result<()>

Like WriteStr::write_str but writes from a TextStr.
source§

fn write_text_substr(&mut self, buf: &TextSubstr) -> Result<(), Error>

Like WriteStr::write_str but writes from a TextSubstr.
source§

impl Terminal for OutputTextStream

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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> GetSetFdFlags for T

source§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
source§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
source§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
source§

impl<T, U> Into<U> for T
where 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 T
where 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 T
where 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.