amplify_derive/
as_any.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//
7// To the extent possible under law, the author(s) have dedicated all
8// copyright and related and neighboring rights to this software to
9// the public domain worldwide. This software is distributed without
10// any warranty.
11//
12// You should have received a copy of the MIT License
13// along with this software.
14// If not, see <https://opensource.org/licenses/MIT>.
15
16use proc_macro2::TokenStream as TokenStream2;
17use syn::{DeriveInput, Result};
18
19pub(crate) fn inner(input: DeriveInput) -> Result<TokenStream2> {
20    let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
21    let ident_name = &input.ident;
22
23    Ok(quote! {
24        #[automatically_derived]
25        impl #impl_generics ::amplify::AsAny for #ident_name #ty_generics #where_clause {
26           fn as_any(&self) -> &dyn ::core::any::Any {
27                self as &dyn ::core::any::Any
28            }
29        }
30    })
31}