pub struct Diagnostic<E = Error> {
pub error: Box<E>,
pub detail: Box<Detail>,
}Expand description
Error diagnostics. Display user-friendly error snippets with Display.
A diagnostic is a wrapper around an error with extra contextual metadata: the source, the declaration name, the span, …
Fields§
§error: Box<E>§detail: Box<Detail>Implementations§
Source§impl<E> Diagnostic<E>
impl<E> Diagnostic<E>
Sourcepub fn with_source(self, source: String) -> Self
pub fn with_source(self, source: String) -> Self
Provide the source code from which the error was emitted.
You should also provide the span with Self::with_span.
Sourcepub fn with_span(self, span: Span) -> Self
pub fn with_span(self, span: Span) -> Self
Provide the span (chunk of source code) where the error originated.
You should also provide the source with Self::with_source.
Subsequent calls to this function do not override the span.
Sourcepub fn with_declaration(self, decl: String) -> Self
pub fn with_declaration(self, decl: String) -> Self
Provide the declaration in which the error originated.
Sourcepub fn with_output(self, out: String) -> Self
pub fn with_output(self, out: String) -> Self
Provide the output code that was generated, even if an error was emitted.
Sourcepub fn with_module_path(
self,
path: ModulePath,
disp_name: Option<String>,
) -> Self
pub fn with_module_path( self, path: ModulePath, disp_name: Option<String>, ) -> Self
Provide the module path in which the error was emitted. The disp_name is
usually the file name of the module.
Sourcepub fn with_sourcemap(self, sourcemap: &impl SourceMap) -> Self
pub fn with_sourcemap(self, sourcemap: &impl SourceMap) -> Self
Add metadata collected by the sourcemap. If the mangled declaration name was set, this will automatically add the source, the module path and the declaration name.
Source§impl<E: Error> Diagnostic<E>
impl<E: Error> Diagnostic<E>
pub fn render_plain(&self) -> String
pub fn render_colored(&self) -> String
Source§impl<E> Diagnostic<E>
impl<E> Diagnostic<E>
Sourcepub fn colored(&self, colored: bool) -> ColoredDiagnostic<'_, E>
pub fn colored(&self, colored: bool) -> ColoredDiagnostic<'_, E>
A std::fmt::Display adapter to get a colored output (with ANSI codes).
Diagnostics auto-detect if colors are supported using anstream.
With this adapter, you can force a colored or non-colored output.
Trait Implementations§
Source§impl<E: Debug> Debug for Diagnostic<E>
impl<E: Debug> Debug for Diagnostic<E>
Source§impl<E: Error> Display for Diagnostic<E>
impl<E: Error> Display for Diagnostic<E>
Source§impl<E: Error> Error for Diagnostic<E>
impl<E: Error> Error for Diagnostic<E>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<CondCompError> for Diagnostic<Error>
impl From<CondCompError> for Diagnostic<Error>
Source§fn from(error: CondCompError) -> Self
fn from(error: CondCompError) -> Self
Source§impl From<Diagnostic> for ResolveError
impl From<Diagnostic> for ResolveError
Source§fn from(source: Diagnostic<Error>) -> Self
fn from(source: Diagnostic<Error>) -> Self
Source§impl From<Diagnostic> for Error
impl From<Diagnostic> for Error
Source§fn from(source: Diagnostic<Error>) -> Self
fn from(source: Diagnostic<Error>) -> Self
Source§impl From<ImportError> for Diagnostic<Error>
impl From<ImportError> for Diagnostic<Error>
Source§fn from(error: ImportError) -> Self
fn from(error: ImportError) -> Self
Source§impl From<ResolveError> for Diagnostic<Error>
impl From<ResolveError> for Diagnostic<Error>
Source§fn from(error: ResolveError) -> Self
fn from(error: ResolveError) -> Self
Source§impl From<UsageError> for Diagnostic<Error>
impl From<UsageError> for Diagnostic<Error>
Source§fn from(error: UsageError) -> Self
fn from(error: UsageError) -> Self
Source§impl From<ValidateError> for Diagnostic<Error>
impl From<ValidateError> for Diagnostic<Error>
Source§fn from(error: ValidateError) -> Self
fn from(error: ValidateError) -> Self
Auto Trait Implementations§
impl<E> Freeze for Diagnostic<E>
impl<E> RefUnwindSafe for Diagnostic<E>where
E: RefUnwindSafe,
impl<E> Send for Diagnostic<E>where
E: Send,
impl<E> Sync for Diagnostic<E>where
E: Sync,
impl<E> Unpin for Diagnostic<E>
impl<E> UnsafeUnpin for Diagnostic<E>
impl<E> UnwindSafe for Diagnostic<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more