use quote::quote; use crate::util::syn_path_to_string; pub fn generate( visibility: &syn::Visibility, engine_crate_path: &syn::Path, ) -> proc_macro2::TokenStream { match visibility { syn::Visibility::Public(_) => { quote! { #engine_crate_path::reflection::Visibility::Pub } } syn::Visibility::Restricted(vis_restricted) => { let vis_scope = if vis_restricted.in_token.is_some() { let in_path = syn_path_to_string(&vis_restricted.path); quote! { #engine_crate_path::reflection::VisibilityScope::In( std::borrow::Cow::Borrowed(#in_path) ) } } else { let Some(scope) = vis_restricted.path.get_ident() else { unreachable!(); }; if scope == "crate" { quote! { #engine_crate_path::reflection::VisibilityScope::Crate } } else if scope == "super" { quote! { #engine_crate_path::reflection::VisibilityScope::Super } } else if scope == "self" { quote! { #engine_crate_path::reflection::VisibilityScope::SelfModule } } else { unreachable!(); } }; quote! { #engine_crate_path::reflection::Visibility::PubScoped(#vis_scope) } } syn::Visibility::Inherited => { quote! { #engine_crate_path::reflection::Visibility::Private } } } }