Struct smart_config_commands::Printer

source ·
pub struct Printer<W: RawStream> { /* private fields */ }
Expand description

Wrapper around an I/O writer. Will style the output with ANSI sequences if appropriate.

Internally, the printer is based on anstream / anstyle; see their docs to find out how styling support is detected by default. (TL;DR: based on NO_COLOR, CLICOLOR_FORCE and CLICOLOR env vars, and whether the output is a terminal.) If this detection doesn’t work for you, you can always create a fully custom Printer.

Implementations§

source§

impl<W: RawStream + AsLockedWrite> Printer<W>

source

pub fn print_debug( self, repo: &ConfigRepository<'_>, filter: impl FnMut(ParamRef<'_>) -> bool, ) -> Result<Result<(), ParseErrors>>

Prints debug info for all param values in the provided repo. If params fail to deserialize, corresponding error(s) are output as well.

§Errors
  • Propagates I/O errors.
  • Returns the exhaustive parsing result. Depending on the application, some parsing errors (e.g., missing params for optional configs) may not be fatal.
source§

impl<W: RawStream + AsLockedWrite> Printer<W>

source

pub fn print_help( self, schema: &ConfigSchema, filter: impl FnMut(ParamRef<'_>) -> bool, ) -> Result<()>

Prints help on config params in the provided schema. Params can be filtered by the supplied predicate.

§Errors

Propagates I/O errors.

source§

impl<W: RawStream + AsLockedWrite> Printer<W>

source

pub fn print_json(&mut self, json: &Value) -> Result<()>

Outputs JSON with syntax highlighting.

§Errors

Proxies I/O errors.

source

pub fn print_yaml(&mut self, json: &Value) -> Result<()>

Outputs YAML adhering to the JSON model with syntax highlighting.

§Errors

Proxies I/O errors.

source§

impl Printer<StdoutLock<'static>>

source

pub fn stdout() -> Self

Creates a printer to stdout. The stdout is locked while the printer is alive!

source§

impl Printer<StderrLock<'static>>

source

pub fn stderr() -> Self

Creates a printer to stderr. The stderr is locked while the printer is alive!

source§

impl<W: RawStream> Printer<W>

source

pub fn custom(writer: AutoStream<W>) -> Self

Creates a custom printer.

Trait Implementations§

source§

impl<W: Debug + RawStream> Debug for Printer<W>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Printer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Printer<W>
where W: RefUnwindSafe,

§

impl<W> Send for Printer<W>
where W: Send,

§

impl<W> Sync for Printer<W>
where W: Sync,

§

impl<W> Unpin for Printer<W>
where W: Unpin,

§

impl<W> UnwindSafe for Printer<W>
where W: UnwindSafe,

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more