amplify_derive/error.rs
1// Rust language amplification derive library providing multiple generic trait
2// implementations, type wrappers, derive macros and other language enhancements
3//
4// Written in 2019-2020 by
5// Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
6// Elichai Turkel <elichai.turkel@gmail.com>
7//
8// To the extent possible under law, the author(s) have dedicated all
9// copyright and related and neighboring rights to this software to
10// the public domain worldwide. This software is distributed without
11// any warranty.
12//
13// You should have received a copy of the MIT License
14// along with this software.
15// If not, see <https://opensource.org/licenses/MIT>.
16
17use proc_macro2::TokenStream as TokenStream2;
18use syn::{DeriveInput, Result};
19
20pub(crate) fn inner(input: DeriveInput) -> Result<TokenStream2> {
21 let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
22 let ident_name = &input.ident;
23
24 Ok(quote! {
25 #[automatically_derived]
26 impl #impl_generics ::std::error::Error for #ident_name #ty_generics #where_clause {
27 }
28
29 #[automatically_derived]
30 impl #impl_generics From<#ident_name #ty_generics> for String #where_clause {
31 fn from(err: #ident_name #ty_generics) -> Self {
32 err.to_string()
33 }
34 }
35 })
36}