Struct color_eyre::section::IndentedSection[][src]

pub struct IndentedSection<H, B> { /* fields omitted */ }

An indented section with a header for an error report

Details

This helper provides two functions to help with constructing nicely formatted error reports. First, it handles indentation of every line of the body for you, and makes sure it is consistent with the rest of color-eyre’s output. Second, it omits outputting the header if the body itself is empty, preventing unnecessary pollution of the report for sections with dynamic content.

Examples

use color_eyre::{eyre::eyre, SectionExt, Help, eyre::Report};
use std::process::Command;
use tracing::instrument;

trait Output {
    fn output2(&mut self) -> Result<String, Report>;
}

impl Output for Command {
    #[instrument]
    fn output2(&mut self) -> Result<String, Report> {
        let output = self.output()?;

        let stdout = String::from_utf8_lossy(&output.stdout);

        if !output.status.success() {
            let stderr = String::from_utf8_lossy(&output.stderr);
            Err(eyre!("cmd exited with non-zero status code"))
                .with_section(move || stdout.trim().to_string().header("Stdout:"))
                .with_section(move || stderr.trim().to_string().header("Stderr:"))
        } else {
            Ok(stdout.into())
        }
    }
}

Trait Implementations

impl<H, B> Display for IndentedSection<H, B> where
    H: Display + Send + Sync + 'static,
    B: Display + Send + Sync + 'static, 
[src]

Auto Trait Implementations

impl<H, B> RefUnwindSafe for IndentedSection<H, B> where
    B: RefUnwindSafe,
    H: RefUnwindSafe

impl<H, B> Send for IndentedSection<H, B> where
    B: Send,
    H: Send

impl<H, B> Sync for IndentedSection<H, B> where
    B: Sync,
    H: Sync

impl<H, B> Unpin for IndentedSection<H, B> where
    B: Unpin,
    H: Unpin

impl<H, B> UnwindSafe for IndentedSection<H, B> where
    B: UnwindSafe,
    H: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<D> OwoColorize for D[src]

impl<T> SectionExt for T where
    T: Display + Send + Sync + 'static, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.