Skip to main content

FrontError

Struct FrontError 

Source
pub struct FrontError {
    pub line: usize,
    pub col: usize,
    pub msg: String,
    pub code: Box<Error>,
    /* private fields */
}
Expand description

Unified front-end error. line == 0 means “no position” (e.g. a purely semantic error).

The error is identified by a stable code (Error::code), not by a sentence: msg is the rendering for the locale that was requested (English by default), and code is what tests and callers match on. Messages that have not been catalogued yet carry code == Error::Message(..) with their original text — an explicit staging marker, not a silent fallback.

Fields§

§line: usize§col: usize§msg: String

Rendering in i18n::Locale::En unless FrontError::in_locale produced a copy.

§code: Box<Error>

Implementations§

Source§

impl FrontError

Source

pub fn new(line: usize, col: usize, msg: impl Into<Error>) -> Self

Source

pub fn plain(msg: impl Into<Error>) -> Self

Source

pub fn coded(code: Error, args: &[&str], line: usize, col: usize) -> Self

A catalogued error: the message is rendered from the code and its arguments.

The arguments are kept, so FrontError::in_locale can re-render the same error in any of the nine languages without the caller having to hold them again.

Source

pub fn render_in(&self, language: Locale) -> String

Renders this error in language. Uncatalogued (Raw) errors keep their text.

Source

pub fn in_locale(&self, language: Locale) -> Self

Convenience: a copy whose msg is rendered in language.

Source

pub fn localized(&self) -> Self

Convenience: a copy rendered in HIMARI_LANG/LC_ALL/LANG, or English under no_std.

Source

pub fn render_with_source(&self, origin: &str, src: &str) -> String

Contextual rendering: source line + caret.

Given only line:col, the user has to count by hand which character is in column 17; quoting that line and drawing a ^ under the position is an editor-grade experience, and it costs only a few lines of code.

Source

pub fn render(&self, origin: &str) -> String

Trait Implementations§

Source§

impl Clone for FrontError

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 FrontError

Source§

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

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

impl From<Error> for FrontError

Source§

fn from(code: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FrontError> for Error

Source§

fn from(err: FrontError) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for FrontError

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 FrontError

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