pub struct Diagnostic { /* private fields */ }Expand description
A build-time template-authoring diagnostic.
Construct with Diagnostic::error / Diagnostic::warning, attach
context with the builder methods, then return it inside
crate::ParserError::Template. The library never colors or prints it; the
CLI reads the fields via the getters and renders them, while other hosts use
the plain fmt::Display text.
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn error(title: impl Into<String>) -> Diagnostic
pub fn error(title: impl Into<String>) -> Diagnostic
Start a fatal error diagnostic. Titles are short and lowercase by
convention (e.g. invalid @click handler).
Sourcepub fn warning(title: impl Into<String>) -> Diagnostic
pub fn warning(title: impl Into<String>) -> Diagnostic
Start a non-fatal warning diagnostic.
Rendered with the same location/snippet/help: layout as an error, but
the build continues (e.g. an unthemed literal-fallback CSS token).
Sourcepub fn code(self, code: &'static str) -> Diagnostic
pub fn code(self, code: &'static str) -> Diagnostic
Sourcepub fn component(self, component: impl Into<String>) -> Diagnostic
pub fn component(self, component: impl Into<String>) -> Diagnostic
Name the owning component template (e.g. mail-inbox-page).
Sourcepub fn element(self, element: impl Into<String>) -> Diagnostic
pub fn element(self, element: impl Into<String>) -> Diagnostic
Name the offending element tag (e.g. button), when known.
Sourcepub fn snippet(self, snippet: impl Into<String>) -> Diagnostic
pub fn snippet(self, snippet: impl Into<String>) -> Diagnostic
Attach the offending source snippet (e.g. @click="bad()").
Sourcepub fn help(self, help: impl Into<String>) -> Diagnostic
pub fn help(self, help: impl Into<String>) -> Diagnostic
Attach a help: hint describing the fix.
Sourcepub fn position(self, line: usize, column: usize) -> Diagnostic
pub fn position(self, line: usize, column: usize) -> Diagnostic
Attach the 1-based (line, column) of the offending source location.
Sourcepub fn at_offset(self, source: &str, offset: usize) -> Diagnostic
pub fn at_offset(self, source: &str, offset: usize) -> Diagnostic
Attach the source location computed from a byte offset into source.
Convenience over Diagnostic::position for callers that hold the
source text and a byte offset (e.g. an element’s start). Computes the
1-based line and column in a single forward scan.
Sourcepub fn error_code(&self) -> Option<&'static str>
pub fn error_code(&self) -> Option<&'static str>
The stable, machine-readable error code, if set.
Sourcepub fn component_name(&self) -> Option<&str>
pub fn component_name(&self) -> Option<&str>
The owning component tag, if set.
Sourcepub fn element_name(&self) -> Option<&str>
pub fn element_name(&self) -> Option<&str>
The offending element tag, if set.
Sourcepub fn snippet_text(&self) -> Option<&str>
pub fn snippet_text(&self) -> Option<&str>
The offending source snippet, if set.
Sourcepub fn position_line_column(&self) -> Option<(usize, usize)>
pub fn position_line_column(&self) -> Option<(usize, usize)>
The 1-based (line, column) of the offending source location, if known.
Sourcepub fn location(&self) -> Option<String>
pub fn location(&self) -> Option<String>
Render the location line content (already including its leading marker), if any.
When a source position is known it is reported rustc-style as
--> owner:line:column (the owner is the entry file or component
tag), which is compact and recognizable. Without a position it falls
back to a descriptive in component <c> · element <e> form. Returned so
callers (e.g. the CLI) can render the location on its own styled line.
Sourcepub fn body(&self) -> String
pub fn body(&self) -> String
Render the message body — everything after the severity label: title,
location, offending snippet, and help: hint, each on its own line.
Used by callers that supply their own leading label (e.g. the dev
server prints build error: {body}) so the severity word isn’t
duplicated. fmt::Display prepends the severity to this body.
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl Display for Diagnostic
impl Display for Diagnostic
impl Eq for Diagnostic
Source§impl From<Diagnostic> for ParserError
impl From<Diagnostic> for ParserError
Source§fn from(diagnostic: Diagnostic) -> ParserError
fn from(diagnostic: Diagnostic) -> ParserError
Source§impl PartialEq for Diagnostic
impl PartialEq for Diagnostic
impl StructuralPartialEq for Diagnostic
Auto Trait Implementations§
impl Freeze for Diagnostic
impl RefUnwindSafe for Diagnostic
impl Send for Diagnostic
impl Sync for Diagnostic
impl Unpin for Diagnostic
impl UnsafeUnpin 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