mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 04:47:56 +00:00
Retain Rust code items from mod decorated with subxt attribute (#721)
* refactor: Simplify collecting type substitutes * Simplify ItemMod::from * Preserve inner Rust items when expanding the subxt::subxt macro * No named lifetimes * Update codegen/src/api/mod.rs Co-authored-by: Andrew Jones <ascjones@gmail.com> * Move passing UI tests under `ui_tests` Co-authored-by: Andrew Jones <ascjones@gmail.com>
This commit is contained in:
+15
-5
@@ -26,16 +26,13 @@ impl From<syn::ItemMod> for ItemMod {
|
||||
abort!(module, "out-of-line subxt modules are not supported",)
|
||||
}
|
||||
};
|
||||
let items = items
|
||||
.into_iter()
|
||||
.map(<Item as From<syn::Item>>::from)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Self {
|
||||
vis: module.vis,
|
||||
mod_token: module.mod_token,
|
||||
ident: module.ident,
|
||||
brace,
|
||||
items,
|
||||
items: items.into_iter().map(From::from).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,6 +54,10 @@ impl ItemMod {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn rust_items(&self) -> impl Iterator<Item = &syn::Item> {
|
||||
self.items.iter().filter_map(Item::as_rust)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
@@ -66,6 +67,15 @@ pub enum Item {
|
||||
Subxt(SubxtItem),
|
||||
}
|
||||
|
||||
impl Item {
|
||||
pub fn as_rust(&self) -> Option<&syn::Item> {
|
||||
match self {
|
||||
Item::Rust(item) => Some(item),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<syn::Item> for Item {
|
||||
fn from(item: syn::Item) -> Self {
|
||||
if let syn::Item::Use(ref use_) = item {
|
||||
|
||||
Reference in New Issue
Block a user