use crate::writers::WriterExt;
use std::fmt::{self, Display};
#[cfg(feature = "issue-url")]
pub(crate) mod github;
pub(crate) mod help;
#[allow(missing_debug_implementations)]
pub struct IndentedSection<H, B> {
header: H,
body: B,
}
impl<H, B> fmt::Display for IndentedSection<H, B>
where
H: Display + Send + Sync + 'static,
B: Display + Send + Sync + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use std::fmt::Write;
let mut headered = f.header(&self.header);
let headered = headered.ready();
let mut headered = headered.header("\n");
let mut headered = headered.ready();
let mut indented = indenter::indented(&mut headered)
.with_format(indenter::Format::Uniform { indentation: " " });
write!(&mut indented, "{}", self.body)?;
Ok(())
}
}
pub trait SectionExt: Sized {
fn header<C>(self, header: C) -> IndentedSection<C, Self>
where
C: Display + Send + Sync + 'static;
}
impl<T> SectionExt for T
where
T: Display + Send + Sync + 'static,
{
fn header<C>(self, header: C) -> IndentedSection<C, Self>
where
C: Display + Send + Sync + 'static,
{
IndentedSection { body: self, header }
}
}
pub trait Section: crate::private::Sealed {
type Return;
fn section<D>(self, section: D) -> Self::Return
where
D: Display + Send + Sync + 'static;
fn with_section<D, F>(self, section: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D;
fn error<E>(self, error: E) -> Self::Return
where
E: std::error::Error + Send + Sync + 'static;
fn with_error<E, F>(self, error: F) -> Self::Return
where
F: FnOnce() -> E,
E: std::error::Error + Send + Sync + 'static;
fn note<D>(self, note: D) -> Self::Return
where
D: Display + Send + Sync + 'static;
fn with_note<D, F>(self, f: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D;
fn warning<D>(self, warning: D) -> Self::Return
where
D: Display + Send + Sync + 'static;
fn with_warning<D, F>(self, f: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D;
fn suggestion<D>(self, suggestion: D) -> Self::Return
where
D: Display + Send + Sync + 'static;
fn with_suggestion<D, F>(self, f: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D;
fn suppress_backtrace(self, suppress: bool) -> Self::Return;
}
pub trait PanicMessage: Send + Sync + 'static {
fn display(&self, pi: &std::panic::PanicInfo<'_>, f: &mut fmt::Formatter<'_>) -> fmt::Result;
}