[−][src]Struct color_eyre::section::IndentedSection
An indenteted 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]
H: Display + Send + Sync + 'static,
B: Display + Send + Sync + 'static,
Auto Trait Implementations
impl<H, B> RefUnwindSafe for IndentedSection<H, B> where
B: RefUnwindSafe,
H: RefUnwindSafe,
B: RefUnwindSafe,
H: RefUnwindSafe,
impl<H, B> Send for IndentedSection<H, B> where
B: Send,
H: Send,
B: Send,
H: Send,
impl<H, B> Sync for IndentedSection<H, B> where
B: Sync,
H: Sync,
B: Sync,
H: Sync,
impl<H, B> Unpin for IndentedSection<H, B> where
B: Unpin,
H: Unpin,
B: Unpin,
H: Unpin,
impl<H, B> UnwindSafe for IndentedSection<H, B> where
B: UnwindSafe,
H: UnwindSafe,
B: UnwindSafe,
H: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SectionExt for T where
T: Display + Send + Sync + 'static,
[src]
T: Display + Send + Sync + 'static,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,