Printer

Struct 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_markdown_reference( self, schema: &ConfigSchema, options: &MarkdownOptions, filter: impl FnMut(ParamRef<'_>) -> bool, ) -> Result<()>

Prints a Markdown reference for config params in the provided schema.

Params can be filtered by the supplied predicate. Enum tag params are rendered together with other matching params in the same config so that conditional fields have useful context.

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

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.
§

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