1 stable release
1.0.0 | Jun 7, 2022 |
---|
#119 in #syn
36 downloads per month
Used in 3 crates
(via to-syn-error)
4KB
68 lines
to-syn-error
The util for convertion to error of syn.
What this crate should be used
this is for developping the macro of Rust, largely. Add, this is useful on conversion between the error that developers define and the error of syn crate.
How to use
Before developping with this crate, Two crates must be installed the project with Cargo.toml
.
[dependencies]
# --- some crates ---
to-syn-error="1.0"
# the following is important!
syn="1.0"
proc_macro2="1.0"
Then, as first on a writing a code, declare an enum for error handling with thiserror. Then, add the trait of this crate into the derive macros.
use thiserror::Error;
use to_syn_error::ToSynError;
#[derive(Error,Debug,ToSynError)]
enum ParseError{
#[error("it is occurred that is wrong.")]
Something
}
As the end, the error can trans as the error of syn.
let input: syn::parse::ParseStream;
let span = input.span();
let error_syn = ParseError::Something.to_syn_error(span);
License
MIT
Dependencies
~0.4–0.8MB
~20K SLoC