Find cxx::bridge mod nested inside another mod

This commit is contained in:
David Tolnay 2020-05-11 01:13:33 -07:00
parent b4dba23910
commit 2498af39f2
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -4,7 +4,14 @@ use quote::quote;
use syn::{Attribute, File, Item};
pub(super) fn find_bridge_mod(syntax: File) -> Result<Input> {
for item in syntax.items {
match scan(syntax.items)? {
Some(input) => Ok(input),
None => Err(Error::NoBridgeMod),
}
}
fn scan(items: Vec<Item>) -> Result<Option<Input>> {
for item in items {
if let Item::Mod(item) = item {
for attr in &item.attrs {
let path = &attr.path;
@ -19,12 +26,17 @@ pub(super) fn find_bridge_mod(syntax: File) -> Result<Input> {
}
};
let namespace = parse_args(attr)?;
return Ok(Input { namespace, module });
return Ok(Some(Input { namespace, module }));
}
}
if let Some(module) = item.content {
if let Some(input) = scan(module.1)? {
return Ok(Some(input));
}
}
}
}
Err(Error::NoBridgeMod)
Ok(None)
}
fn parse_args(attr: &Attribute) -> syn::Result<Namespace> {