pub struct ShellWriter<W: Write> { /* private fields */ }
Expand description

A writer of var=value pairs.

See ShellWriter::new().

Implementations§

source§

impl<W: Write> ShellWriter<W>

source

pub fn new<P: Display>(writer: W, prefix: P) -> 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");
source

pub fn write_var<K: Display, V: Display>(&self, var: K, value: V)

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.

source

pub fn write_var_debug<K: Display, V: Debug>(&self, var: K, value: V)

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.

source

pub fn write_vars<V: ShellVars>(&self, vars: &V)

Write an object with the ShellVars trait. Mostly used with Self::group() and Self::group_n().

source

pub fn group<G: Display>(&self, group: G) -> Self

Generate a sub-writer with this group name. Example output:

prefix_group_var=value
source

pub fn group_n<P: Display, N: Display>(&self, prefix: P, n: N) -> Self

Generate a sub-writer with this group name and number. Example output:

prefix_groupN_var=value
source§

impl ShellWriter<Stdout>

source

pub fn with_prefix<P: Display>(prefix: P) -> Self

Create a new ShellWriter for io::stdout() and a prefix.

Trait Implementations§

source§

impl<W: Clone + Write> Clone for ShellWriter<W>

source§

fn clone(&self) -> ShellWriter<W>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<W: Write + Debug> Debug for ShellWriter<W>

source§

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

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

impl Default for ShellWriter<Stdout>

source§

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§

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, 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.