pub struct Diagnostic {
pub kind: DiagnosticKind,
pub message: String,
pub span: Option<Span>,
pub notes: Vec<DiagnosticNote>,
pub helps: Vec<DiagnosticHelp>,
}
Expand description
Additional contextual information intended for end users, to help them understand what went wrong by providing human-readable messages, and locations in the source query that relate to the error in some way.
You can think of a single Diagnostic
as a single “block” of output from
rustc. i.e. either an error or a warning, optionally with some notes and
help messages.
Example:
let span = Some(Span {
start: Location{ line: 2, column: 1 },
end: Location{ line: 4, column: 15 }
});
let diagnostic = Diagnostic::new_error("Something went wrong", span)
.with_help("Have you tried turning it on and off again?", None);
Fields§
§kind: DiagnosticKind
§message: String
§span: Option<Span>
§notes: Vec<DiagnosticNote>
§helps: Vec<DiagnosticHelp>
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn new_error(message: impl Into<String>, span: Option<Span>) -> Self
pub fn new_error(message: impl Into<String>, span: Option<Span>) -> Self
Creates a new Diagnostic
for a fatal error that prevents the SQL
query from being planned and executed. Optionally takes in a Span
to
describe the location in the source code that caused the error, should
be provided when available.
Sourcepub fn new_warning(message: impl Into<String>, span: Option<Span>) -> Self
pub fn new_warning(message: impl Into<String>, span: Option<Span>) -> Self
Creates a new Diagnostic
for a NON-fatal warning, such as a
performance problem, or possible cause for undesired results. Optionally
takes in a Span
to describe the location in the source code that
caused the error, should be provided when available.
Sourcepub fn add_note(&mut self, message: impl Into<String>, span: Option<Span>)
pub fn add_note(&mut self, message: impl Into<String>, span: Option<Span>)
Adds a “note” to the Diagnostic
, which can have zero or many. A “note”
helps contextualize the error and helps the end user understand why it
occurred. It can refer to an arbitrary location in the SQL query, or to
no location.
Sourcepub fn add_help(&mut self, message: impl Into<String>, span: Option<Span>)
pub fn add_help(&mut self, message: impl Into<String>, span: Option<Span>)
Adds a “help” to the Diagnostic
, which can have zero or many. A
“help” helps the user understand how they might fix the error or
warning. It can refer to an arbitrary location in the SQL query, or to
no location.
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for Diagnostic
impl RefUnwindSafe for Diagnostic
impl Send for Diagnostic
impl Sync for Diagnostic
impl Unpin for Diagnostic
impl UnwindSafe for Diagnostic
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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