pub struct JsonWriter<T> { /* private fields */ }
Expand description
Type-safe machine output implementation of crate::ToolIO
Implementations§
Source§impl<T> JsonWriter<T>
impl<T> JsonWriter<T>
Sourcepub fn new_buffers<'a, O, E>(
format: Option<Format>,
stdout: O,
stderr: E,
) -> Self
pub fn new_buffers<'a, O, E>( format: Option<Format>, stdout: O, stderr: E, ) -> Self
Create a new writer that doesn’t support machine output at all, with the given streams underlying it.
Sourcepub fn new(format: Option<Format>) -> Self
pub fn new(format: Option<Format>) -> Self
Create a new Writer with the specified format.
Passing None for format implies no output via the machine function.
Sourcepub fn new_test(format: Option<Format>, test_buffers: &TestBuffers) -> Self
pub fn new_test(format: Option<Format>, test_buffers: &TestBuffers) -> Self
Returns a writer backed by string buffers that can be extracted after the writer is done with
Sourcepub fn simple_writer(self) -> Writer ⓘ
pub fn simple_writer(self) -> Writer ⓘ
Allow using this writer as a SimpleWriter. This is useful for calling other tools that do not use JsonWriter.
pub fn stderr(&mut self) -> &mut Box<dyn Write>
Source§impl<T> JsonWriter<T>where
T: Serialize,
impl<T> JsonWriter<T>where
T: Serialize,
Sourcepub fn machine_many<I: IntoIterator<Item = T>>(
&mut self,
output: I,
) -> Result<()>
pub fn machine_many<I: IntoIterator<Item = T>>( &mut self, output: I, ) -> Result<()>
Write the items from the iterable object to standard output.
This is a no-op if is_machine
returns false.
Sourcepub fn machine(&mut self, output: &T) -> Result<()>
pub fn machine(&mut self, output: &T) -> Result<()>
Write the item to standard output.
This is a no-op if is_machine
returns false.
Sourcepub fn machine_or<D: Display>(&mut self, value: &T, or: D) -> Result<()>
pub fn machine_or<D: Display>(&mut self, value: &T, or: D) -> Result<()>
If this object is outputting machine output, print the item’s machine representation to stdout. Otherwise, print the display item given.
Sourcepub fn machine_or_write<D: Display>(&mut self, value: &T, or: D) -> Result<()>
pub fn machine_or_write<D: Display>(&mut self, value: &T, or: D) -> Result<()>
If this object is outputting machine output, print the item’s machine
representation to stdout. Otherwise, write!
the display item given.
Sourcepub fn machine_or_else<F, R>(&mut self, value: &T, f: F) -> Result<()>
pub fn machine_or_else<F, R>(&mut self, value: &T, f: F) -> Result<()>
If this object is outputting machine output, prints the item’s machine representation to stdout. Otherwise, call the closure with the object and print the result.
pub fn format(&self) -> Option<Format>
pub fn formatted<J: Serialize>(&mut self, output: &J) -> Result<()>
Trait Implementations§
Source§impl<T> ToolIO for JsonWriter<T>where
T: Serialize,
impl<T> ToolIO for JsonWriter<T>where
T: Serialize,
Source§type OutputItem = T
type OutputItem = T
Self::item
call (or
any machine output writing functions that may be added by an
implementation)Source§fn is_machine_supported() -> bool
fn is_machine_supported() -> bool
Source§fn is_machine(&self) -> bool
fn is_machine(&self) -> bool
Source§fn stderr(&mut self) -> &mut Box<dyn Write>
fn stderr(&mut self) -> &mut Box<dyn Write>
Source§fn item(&mut self, value: &T) -> Result<()>where
T: Display,
fn item(&mut self, value: &T) -> Result<()>where
T: Display,
Source§fn has_schema() -> bool
fn has_schema() -> bool
fn try_print_schema(&mut self) -> Result<()>
Source§impl<T> Write for JsonWriter<T>where
T: Serialize,
impl<T> Write for JsonWriter<T>where
T: Serialize,
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
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)