Struct syn::parse::Error [−][src]
pub struct Error { /* fields omitted */ }
Error returned when a Syn parser cannot parse the input tokens.
Refer to the module documentation for details about parsing in Syn.
This type is available if Syn is built with the "parsing"
feature.
Methods
impl Error
[src]
impl Error
pub fn new<T: Display>(span: Span, message: T) -> Self
[src]
pub fn new<T: Display>(span: Span, message: T) -> Self
Usually the ParseStream::error
method will be used instead, which
automatically uses the correct span from the current position of the
parse stream.
Use Error::new
when the error needs to be triggered on some span other
than where the parse stream is currently positioned.
Example
#[macro_use] extern crate syn; use syn::{Ident, LitStr}; use syn::parse::{Error, ParseStream, Result}; // Parses input that looks like `name = "string"` where the key must be // the identifier `name` and the value may be any string literal. // Returns the string literal. fn parse_name(input: ParseStream) -> Result<LitStr> { let name_token: Ident = input.parse()?; if name_token != "name" { // Trigger an error not on the current position of the stream, // but on the position of the unexpected identifier. return Err(Error::new(name_token.span(), "expected `name`")); } input.parse::<Token![=]>()?; let s: LitStr = input.parse()?; Ok(s) }
pub fn span(&self) -> Span
[src]
pub fn span(&self) -> Span
pub fn to_compile_error(&self) -> TokenStream
[src]
pub fn to_compile_error(&self) -> TokenStream
Render the error as an invocation of compile_error!
.
The parse_macro_input!
macro provides a convenient way to invoke
this method correctly in a procedural macro.
Trait Implementations
impl Debug for Error
[src]
impl Debug for Error
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for Error
[src]
impl Clone for Error
fn clone(&self) -> Error
[src]
fn clone(&self) -> Error
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Display for Error
[src]
impl Display for Error
fn fmt(&self, formatter: &mut Formatter) -> Result
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Error for Error
[src]
impl Error for Error
fn description(&self) -> &str
[src]
fn description(&self) -> &str
This method is soft-deprecated. Read more
fn cause(&self) -> Option<&Error>
1.0.0[src]
fn cause(&self) -> Option<&Error>
The lower-level cause of this error, if any. Read more
impl From<LexError> for Error
[src]
impl From<LexError> for Error