blob: c9e85243cf9ed3e5a7d78f124a80a18f71652791 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 }
}
}
}
|