Skip to main content

ErrorType

Trait ErrorType 

Source
pub trait ErrorType: Error {
    type Span: Span + Default;
    type Message: Display;

    // Required methods
    fn kind(&self) -> Kind;
    fn number(&self) -> &str;
    fn code(&self) -> &str;
    fn primary_span(&self) -> Option<Self::Span>;
    fn primary_message(&self) -> Self::Message;
    fn primary_label(&self) -> Self::Message;
    fn additional(
        &self,
    ) -> Box<dyn Iterator<Item = (Option<Self::Span>, Self::Message, Self::Message)>>;

    // Provided method
    fn primary(&self) -> (Option<Self::Span>, Self::Message, Self::Message) { ... }
}
Expand description

Trait for error types generated by error_type! macro and ErrorType derive macro.

For conversion to other diagnostic types, see ErrorTypeExt.

Required Associated Types§

Source

type Span: Span + Default

The span type associated with the error type.

Source

type Message: Display

The message type associated with the error type.

Required Methods§

Source

fn kind(&self) -> Kind

Get the kind of the error.

Source

fn number(&self) -> &str

Get the number of the error.

Source

fn code(&self) -> &str

Get the code of the error.

Normally the code is a combination of kind short string and number, like “E0”, “W1”, etc.

Source

fn primary_span(&self) -> Option<Self::Span>

Get the primary span of the error.

Source

fn primary_message(&self) -> Self::Message

Get the primary message of the error.

Source

fn primary_label(&self) -> Self::Message

Get the primary label of the error.

Source

fn additional( &self, ) -> Box<dyn Iterator<Item = (Option<Self::Span>, Self::Message, Self::Message)>>

Get additional spans, messages, and labels of the error.

Provided Methods§

Source

fn primary(&self) -> (Option<Self::Span>, Self::Message, Self::Message)

Get the primary diagnostic of the error.

Implementations on Foreign Types§

Source§

impl<T> ErrorType for &T
where T: ErrorType + ?Sized,

Source§

type Span = <T as ErrorType>::Span

Source§

type Message = <T as ErrorType>::Message

Source§

fn kind(&self) -> Kind

Source§

fn number(&self) -> &str

Source§

fn code(&self) -> &str

Source§

fn primary_span(&self) -> Option<<&T as ErrorType>::Span>

Source§

fn primary_message(&self) -> <&T as ErrorType>::Message

Source§

fn primary_label(&self) -> <&T as ErrorType>::Message

Source§

fn primary( &self, ) -> (Option<<&T as ErrorType>::Span>, <&T as ErrorType>::Message, <&T as ErrorType>::Message)

Source§

fn additional( &self, ) -> Box<dyn Iterator<Item = (Option<<&T as ErrorType>::Span>, <&T as ErrorType>::Message, <&T as ErrorType>::Message)>>

Implementors§