diff options
| author | HampusM <hampus@hampusmat.com> | 2026-06-09 00:13:13 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-06-09 00:13:13 +0200 |
| commit | 62fe748a90efc35e9a5839b55b75a3db043102f1 (patch) | |
| tree | 21b96060910e357f1730b44765ed3302d3a25566 /engine-macros/src/reflection/visibility.rs | |
| parent | eaff58026be19c068005d6e90bd9e8cbe985b093 (diff) | |
refactor(engine-macros): split up into multiple modules
Diffstat (limited to 'engine-macros/src/reflection/visibility.rs')
| -rw-r--r-- | engine-macros/src/reflection/visibility.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/engine-macros/src/reflection/visibility.rs b/engine-macros/src/reflection/visibility.rs new file mode 100644 index 0000000..c9e8524 --- /dev/null +++ b/engine-macros/src/reflection/visibility.rs @@ -0,0 +1,45 @@ +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 } + } + } +} |
