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

An output stream for binary output.

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

OutputByteStream 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 OutputByteStream is to use it as a type in a kommand argument or 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 OutputByteStream as an argument should avoid using std::io::stdout, std::println, or anything else which uses standard output implicitly.

Implementations§

source§

impl OutputByteStream

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. Some output streams know their type, though many do not.

Trait Implementations§

source§

impl Bufferable for OutputByteStream

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 OutputByteStream

source§

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

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

impl Write for OutputByteStream

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 OutputByteStream

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

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.