Struct git_status_vars::ShellWriter
source · [−]pub struct ShellWriter<W: Write> { /* private fields */ }
Expand description
A writer of var=value pairs.
See ShellWriter::new()
.
Implementations
sourceimpl<W: Write> ShellWriter<W>
impl<W: Write> ShellWriter<W>
sourcepub fn new(writer: W, prefix: impl Display) -> Self
pub fn new(writer: W, prefix: impl Display) -> Self
Create a new ShellWriter
. The prefix
will be prepended anytime a
var is outputted, e.g. prefixvar=value
.
Generally, you will want to use this like:
use git_status_vars::ShellWriter;
ShellWriter::default().group("group").write_var("var", "value");
// or...
let mut buffer: Vec<u8> = vec![];
ShellWriter::new(&mut buffer, "").group("group").write_var("var", "value");
assert_eq!(buffer, b"group_var=value\n");
sourcepub fn write_var(&self, var: impl Display, value: impl Display)
pub fn write_var(&self, var: impl Display, value: impl Display)
Write var=value. value
will be turned into a string, then quoted for
safe shell insertion. var
will be assumed to be a valid name for a
shell variable.
sourcepub fn write_var_debug(&self, var: impl Display, value: impl Debug)
pub fn write_var_debug(&self, var: impl Display, value: impl Debug)
Write var=value. value
will be formatted into a string using
Debug
, then quoted for safe shell insertion. var
will be assumed
to be a valid name for a shell variable.
sourcepub fn write_vars(&self, vars: &impl ShellVars)
pub fn write_vars(&self, vars: &impl ShellVars)
Write an object with the ShellVars
trait. Mostly used with
Self::group()
and Self::group_n()
.
sourcepub fn group(&self, group: impl Display) -> ShellWriter<W>
pub fn group(&self, group: impl Display) -> ShellWriter<W>
Generate a sub-writer with this group name. Example output:
prefix_group_var=value
sourcepub fn group_n(&self, prefix: impl Display, n: impl Display) -> ShellWriter<W>
pub fn group_n(&self, prefix: impl Display, n: impl Display) -> ShellWriter<W>
Generate a sub-writer with this group name and number. Example output:
prefix_groupN_var=value
Trait Implementations
sourceimpl<W: Clone + Write> Clone for ShellWriter<W>
impl<W: Clone + Write> Clone for ShellWriter<W>
sourcefn clone(&self) -> ShellWriter<W>
fn clone(&self) -> ShellWriter<W>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<W: Write> Debug for ShellWriter<W> where
W: Debug,
impl<W: Write> Debug for ShellWriter<W> where
W: Debug,
sourceimpl Default for ShellWriter<Stdout>
impl Default for ShellWriter<Stdout>
sourcefn default() -> Self
fn default() -> Self
Create a new ShellWriter
for io::stdout()
and no prefix.
Auto Trait Implementations
impl<W> !RefUnwindSafe for ShellWriter<W>
impl<W> !Send for ShellWriter<W>
impl<W> !Sync for ShellWriter<W>
impl<W> Unpin for ShellWriter<W>
impl<W> !UnwindSafe for ShellWriter<W>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more