pub struct ErrorMessage { /* private fields */ }
Expand description
A single error message
Can take additional attachments like help
or
note
.
Implements ToTokensError
and can therefore be used with
MacroOutput
s.
Implementations§
Source§impl ErrorMessage
impl ErrorMessage
Sourcepub fn new(span: impl SpanRanged, msg: impl Display) -> Self
pub fn new(span: impl SpanRanged, msg: impl Display) -> Self
Creates a new error message at the specified span
This function takes a SpanRanged
meaning you can also pass a
Range
<Span>
(i.e. first..last
) for better error
messages on multi token values, for details see
SpanRanged#motivation
If your type implements ToTokens
use ErrorMessage::spanned
instead.
Sourcepub fn spanned(tokens: impl ToTokens, msg: impl Display) -> Self
pub fn spanned(tokens: impl ToTokens, msg: impl Display) -> Self
Creates an error message pointing to the complete token stream tokens
expands to
Sourcepub fn call_site(msg: impl Display) -> Self
pub fn call_site(msg: impl Display) -> Self
Creates a new error message at Span::call_site
prefer
ErrorMessage::new
or ErrorMessage::spanned
with the correct span
for a more helpful output.
Sourcepub fn attachment(self, label: &'static str, msg: impl Display) -> Self
pub fn attachment(self, label: &'static str, msg: impl Display) -> Self
Attaches an additional message to self
reusing the same
span, and the specified label
.
Sourcepub fn error(self, msg: impl Display) -> Self
pub fn error(self, msg: impl Display) -> Self
Attaches a new error
message to self
reusing the same span
Sourcepub fn warning(self, msg: impl Display) -> Self
pub fn warning(self, msg: impl Display) -> Self
Attaches a new warning
message to self
reusing the same span
Trait Implementations§
Source§impl<T: ToTokensError + 'static> Add<T> for ErrorMessage
impl<T: ToTokensError + 'static> Add<T> for ErrorMessage
Source§impl Attachment for ErrorMessage
impl Attachment for ErrorMessage
Source§fn attachment(self, label: &'static str, msg: impl Display) -> Self
fn attachment(self, label: &'static str, msg: impl Display) -> Self
self
reusing the same
span, and the specified label
.Source§impl Debug for ErrorMessage
impl Debug for ErrorMessage
Source§impl Display for ErrorMessage
impl Display for ErrorMessage
Source§impl From<ErrorMessage> for Error
impl From<ErrorMessage> for Error
Source§fn from(error: ErrorMessage) -> Self
fn from(error: ErrorMessage) -> Self
Source§impl From<ErrorMessage> for Error
Available on crate feature syn1
only.
impl From<ErrorMessage> for Error
syn1
only.Source§fn from(value: ErrorMessage) -> Self
fn from(value: ErrorMessage) -> Self
Source§impl From<ErrorMessage> for Error
Available on crate feature syn2
only.
impl From<ErrorMessage> for Error
syn2
only.Source§fn from(value: ErrorMessage) -> Self
fn from(value: ErrorMessage) -> Self
Source§impl ToTokensError for ErrorMessage
impl ToTokensError for ErrorMessage
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
ToTokens::to_tokens
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
ToTokens::to_token_stream
Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
ToTokens::into_token_stream