1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct NativeFnId(pub u32);
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub struct NativeTypeId(pub u32);
13
14pub trait NativeProvider: Send + Sync {
20 fn modules(&self) -> Vec<NativeModule>;
21
22 fn expand(&self, path: &[String]) -> NativeModule;
25
26 fn register_enum_builtins(&self, _enum_def: super::DefId) -> Vec<NativeFnDecl> {
30 Vec::new()
31 }
32
33 fn macro_expander(
37 &self,
38 _path: &[&str],
39 ) -> Option<std::sync::Arc<dyn super::macros::MacroExpander>> {
40 None
41 }
42
43 fn attribute_kind(&self, _path: &[&str]) -> Option<crate::attributes::AttributeKind> {
47 None
48 }
49
50 fn parse_attribute(
53 &self,
54 _path: &[&str],
55 _input: &crate::attributes::AttrInput,
56 ) -> Option<Result<std::sync::Arc<dyn std::any::Any + Send + Sync>, crate::attributes::AttrError>>
57 {
58 None
59 }
60}
61
62impl<T: NativeProvider + ?Sized> NativeProvider for std::sync::Arc<T> {
63 fn modules(&self) -> Vec<NativeModule> {
64 (**self).modules()
65 }
66
67 fn expand(&self, path: &[String]) -> NativeModule {
68 (**self).expand(path)
69 }
70
71 fn register_enum_builtins(&self, enum_def: super::DefId) -> Vec<NativeFnDecl> {
72 (**self).register_enum_builtins(enum_def)
73 }
74
75 fn macro_expander(
76 &self,
77 path: &[&str],
78 ) -> Option<std::sync::Arc<dyn super::macros::MacroExpander>> {
79 (**self).macro_expander(path)
80 }
81
82 fn attribute_kind(&self, path: &[&str]) -> Option<crate::attributes::AttributeKind> {
83 (**self).attribute_kind(path)
84 }
85
86 fn parse_attribute(
87 &self,
88 path: &[&str],
89 input: &crate::attributes::AttrInput,
90 ) -> Option<Result<std::sync::Arc<dyn std::any::Any + Send + Sync>, crate::attributes::AttrError>>
91 {
92 (**self).parse_attribute(path, input)
93 }
94}
95
96impl NativeProvider for Vec<NativeModule> {
98 fn modules(&self) -> Vec<NativeModule> {
99 self.clone()
100 }
101
102 fn expand(&self, path: &[String]) -> NativeModule {
103 panic!("`{}` was not declared lazy", path.join("::"))
104 }
105}
106
107#[derive(Debug, Clone, Default)]
109pub struct NativeModule {
110 pub name: String,
111 pub lazy: bool,
114 pub functions: Vec<NativeFnDecl>,
115 pub types: Vec<NativeTypeDecl>,
116 pub modules: Vec<NativeModule>,
117}
118
119#[derive(Debug, Clone)]
120pub struct NativeFnDecl {
121 pub name: String,
122 pub id: NativeFnId,
123 pub param_names: Vec<String>,
124}
125
126#[derive(Debug, Clone)]
129pub struct NativeTypeDecl {
130 pub name: String,
131 pub id: NativeTypeId,
132 pub functions: Vec<NativeFnDecl>,
133 pub variants: Vec<NativeVariantDecl>,
136}
137
138#[derive(Debug, Clone)]
140pub struct NativeVariantDecl {
141 pub name: String,
142 pub kind: NativeVariantKind,
143 pub repr_value: Option<i64>,
146}
147
148#[derive(Debug, Clone, Copy, PartialEq, Eq)]
151pub enum NativeVariantKind {
152 Unit,
153 Tuple,
154 Named,
155}