Skip to main content

Diagnostic

Struct Diagnostic 

Source
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>

Source

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.

Source

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.

Source

pub fn with_declaration(self, decl: String) -> Self

Provide the declaration in which the error originated.

Source

pub fn with_output(self, out: String) -> Self

Provide the output code that was generated, even if an error was emitted.

Source

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.

Source

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>

Source

pub fn render_plain(&self) -> String

Source

pub fn render_colored(&self) -> String

Source§

impl<E> Diagnostic<E>

Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Error> Display for Diagnostic<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Error> Error for Diagnostic<E>

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<CondCompError> for Diagnostic<Error>

Source§

fn from(error: CondCompError) -> Self

Converts to this type from the input type.
Source§

impl From<Diagnostic> for ResolveError

Source§

fn from(source: Diagnostic<Error>) -> Self

Converts to this type from the input type.
Source§

impl From<Diagnostic> for Error

Source§

fn from(source: Diagnostic<Error>) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Diagnostic<Error>

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Diagnostic<Error>

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ImportError> for Diagnostic<Error>

Source§

fn from(error: ImportError) -> Self

Converts to this type from the input type.
Source§

impl From<ResolveError> for Diagnostic<Error>

Source§

fn from(error: ResolveError) -> Self

Converts to this type from the input type.
Source§

impl From<TomlError> for Diagnostic<Error>

Source§

fn from(error: TomlError) -> Self

Converts to this type from the input type.
Source§

impl From<UsageError> for Diagnostic<Error>

Source§

fn from(error: UsageError) -> Self

Converts to this type from the input type.
Source§

impl From<ValidateError> for Diagnostic<Error>

Source§

fn from(error: ValidateError) -> Self

Converts to this type from the input type.

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.