Skip to main content

Diagnostic

Struct Diagnostic 

Source
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

Source

pub fn error(title: impl Into<String>) -> Self

Start a fatal error diagnostic. Titles are short and lowercase by convention (e.g. invalid @click handler).

Source

pub fn warning(title: impl Into<String>) -> Self

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).

Source

pub fn code(self, code: &'static str) -> Self

Attach a stable, machine-readable error code (e.g. invalid-for-each).

The code is a constant identifier that does not change with the wording of the message, so tools and AI assistants can recognize the error class and apply a deterministic fix. Prefer the constants in codes.

Source

pub fn component(self, component: impl Into<String>) -> Self

Name the owning component template (e.g. mail-inbox-page).

Source

pub fn element(self, element: impl Into<String>) -> Self

Name the offending element tag (e.g. button), when known.

Source

pub fn snippet(self, snippet: impl Into<String>) -> Self

Attach the offending source snippet (e.g. @click="bad()").

Source

pub fn help(self, help: impl Into<String>) -> Self

Attach a help: hint describing the fix.

Source

pub fn position(self, line: usize, column: usize) -> Self

Attach the 1-based (line, column) of the offending source location.

Source

pub fn at_offset(self, source: &str, offset: usize) -> Self

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.

Source

pub fn severity(&self) -> Severity

Severity of this diagnostic.

Source

pub fn error_code(&self) -> Option<&'static str>

The stable, machine-readable error code, if set.

Source

pub fn title(&self) -> &str

The short error title (e.g. invalid @click handler).

Source

pub fn component_name(&self) -> Option<&str>

The owning component tag, if set.

Source

pub fn element_name(&self) -> Option<&str>

The offending element tag, if set.

Source

pub fn snippet_text(&self) -> Option<&str>

The offending source snippet, if set.

Source

pub fn help_text(&self) -> Option<&str>

The help: hint, if set.

Source

pub fn position_line_column(&self) -> Option<(usize, usize)>

The 1-based (line, column) of the offending source location, if known.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Diagnostic

Source§

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

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

impl Display for Diagnostic

Source§

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

Render the plain, color-free report. Hosts that want color (the CLI) read the fields via the getters instead.

Source§

impl Eq for Diagnostic

Source§

impl From<Diagnostic> for ParserError

Source§

fn from(diagnostic: Diagnostic) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Diagnostic

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Diagnostic

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.