Derive derives on Error not ErrorKind
This commit is contained in:
parent
4cb572f64c
commit
1d81b59163
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ctxerr"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
authors = ["Andrey Tkachenko <andrey@aidev.ru>"]
|
||||
repository = "https://github.com/andreytkachenko/ctxerr.git"
|
||||
keywords = ["error", "handling", "thiserror", "context", "backtrace"]
|
||||
@ -15,5 +15,5 @@ resolver = "2"
|
||||
members = ["derive"]
|
||||
|
||||
[dependencies]
|
||||
ctxerr_derive = {version = "0.3.0", path = "derive"}
|
||||
thiserror = "1.0.39"
|
||||
ctxerr_derive = {version = "0.4.0", path = "derive"}
|
||||
thiserror = "1.0.40"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ctxerr_derive"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
authors = ["Andrey Tkachenko <andrey@aidev.ru>"]
|
||||
repository = "https://github.com/andreytkachenko/ctxerr.git"
|
||||
keywords = ["error", "handling", "thiserror", "context", "backtrace"]
|
||||
@ -16,4 +16,4 @@ proc-macro = true
|
||||
[dependencies]
|
||||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
syn = {version = "1", features = ["full"]}
|
||||
syn = {version = "2", features = ["full"]}
|
||||
|
@ -11,7 +11,7 @@ pub fn ctxerr(
|
||||
_metadata: proc_macro::TokenStream,
|
||||
input: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
let ast: DeriveInput = syn::parse(input).unwrap();
|
||||
let mut ast: DeriveInput = syn::parse(input).unwrap();
|
||||
let name = ast.ident.to_string();
|
||||
if !name.ends_with("Kind") {
|
||||
panic!("Ttypename should ends with `Kind`!");
|
||||
@ -19,11 +19,26 @@ pub fn ctxerr(
|
||||
|
||||
let name_ident = &ast.ident;
|
||||
let base_name = Ident::new(&name[0..name.len() - 4], ast.ident.span());
|
||||
let attrs = ast
|
||||
.attrs
|
||||
.drain(..)
|
||||
.filter_map(|x| match x.meta {
|
||||
syn::Meta::List(list) => Some(list.tokens),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let tokens = quote! {
|
||||
pub use __private::*;
|
||||
|
||||
mod __private {
|
||||
use super::*;
|
||||
use ctxerr::thiserror;
|
||||
|
||||
#[derive(Debug, ctxerr::thiserror::Error)]
|
||||
#ast
|
||||
|
||||
#[derive(ctxerr::thiserror::Error)]
|
||||
#[derive(ctxerr::thiserror::Error #(, #attrs)*)]
|
||||
pub struct #base_name {
|
||||
kind: #name_ident,
|
||||
backtrace: Option<std::backtrace::Backtrace>,
|
||||
@ -69,6 +84,7 @@ pub fn ctxerr(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user