Struct StreamWriter

Source
pub struct StreamWriter { /* private fields */ }
Expand description

An unbuffered and unlocked output byte stream, implementing Write, abstracted over the destination of the output.

It primarily consists of a single file handle, and also contains any resources needed to safely hold the file handle live.

Since it is unbuffered, and since many destinations have high per-call overhead, it is often beneficial to wrap this in a BufWriter or LineWriter.

Implementations§

Source§

impl StreamWriter

Source

pub fn stdout() -> Result<Self>

Write to standard output.

Unlike std::io::stdout, this stdout returns a stream which is unbuffered and unlocked.

Since it is unbuffered, it is often beneficial to wrap the resulting StreamWriter in a BufWriter or LineWriter.

This acquires a std::io::StdoutLock (in a non-recursive way) to prevent accesses to std::io::Stdout while this is live, and fails if a StreamWriter or StreamDuplexer for standard output already exists.

Source

pub fn stderr() -> Result<Self>

Write to standard error.

Like std::io::stderr, this stderr returns a stream which is unbuffered. However, unlike std::io::stderr, the stream is also unlocked.

Since it is unbuffered, it is often beneficial to wrap the resulting StreamWriter in a BufWriter or LineWriter.

This acquires a std::io::StderrLock (in a non-recursive way) to prevent accesses to std::io::Stderr while this is live, and fails if a StreamWriter or StreamDuplexer for standard output already exists.

Source

pub fn file<Filelike: IntoFilelike + Read + Write + Seek>( filelike: Filelike, ) -> Self

Write to an open file, taking ownership of it.

This method can be passed a std::fs::File or similar File types.

Source

pub fn tcp_stream<Socketlike: IntoSocketlike>(socketlike: Socketlike) -> Self

Write to an open TCP stream, taking ownership of it.

This method can be passed a std::net::TcpStream or similar TcpStream types.

Source

pub fn pipe_writer(pipe_writer: PipeWriter) -> Self

Write to the writing end of an open pipe, taking ownership of it.

Source

pub fn write_to_command(command: Command) -> Result<Self>

Spawn the given command and write to its standard input. Its standard output is redirected to Stdio::null().

Source

pub fn child_stdin(child_stdin: ChildStdin) -> Self

Write to the given child standard input, taking ownership of it.

Source

pub fn piped_thread(boxed_write: Box<dyn Write + Send>) -> Result<Self>

Write to a boxed Write implementation, taking ownership of it. This works by creating a new thread to read the data through a pipe and write it.

Writes to the pipe aren’t synchronous with writes to the boxed Write implementation. To ensure data is flushed all the way through the thread and into the boxed Write implementation, call flush(), which synchronizes with the thread to ensure that is has completed writing all pending output.

Source

pub fn null() -> Result<Self>

Write to the null device, which ignores all data.

Trait Implementations§

Source§

impl AsHandleOrSocket for StreamWriter

Source§

impl AsRawHandleOrSocket for StreamWriter

Source§

impl Debug for StreamWriter

Source§

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

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

impl Write for StreamWriter

Source§

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

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

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

Flushes 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 Send for StreamWriter

Source§

impl Sync for StreamWriter

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> AsGrip for T

Source§

fn as_grip(&self) -> BorrowedHandleOrSocket<'_>

Extracts the grip.
Source§

impl<T> AsRawGrip for T

Source§

fn as_raw_grip(&self) -> RawHandleOrSocket

Extracts the raw grip.
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>

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>,

Source§

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>,

Source§

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.