+/// Insert ident -> absolute Path resolutions into imports from the given UseTree and path-prefix.
+fn process_use_intern<'a>(u: &'a syn::UseTree, mut path: syn::punctuated::Punctuated<syn::PathSegment, syn::token::Colon2>, imports: &mut HashMap<&'a syn::Ident, syn::Path>) {
+ match u {
+ syn::UseTree::Path(p) => {
+ path.push(syn::PathSegment { ident: p.ident.clone(), arguments: syn::PathArguments::None });
+ process_use_intern(&p.tree, path, imports);
+ },
+ syn::UseTree::Name(n) => {
+ path.push(syn::PathSegment { ident: n.ident.clone(), arguments: syn::PathArguments::None });
+ imports.insert(&n.ident, syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments: path });
+ },
+ syn::UseTree::Group(g) => {
+ for i in g.items.iter() {
+ process_use_intern(i, path.clone(), imports);
+ }
+ },
+ _ => {}
+ }
+}
+
+/// Map all the Paths in a Type into absolute paths given a set of imports (generated via process_use_intern)
+fn resolve_imported_refs(imports: &HashMap<&syn::Ident, syn::Path>, mut ty: syn::Type) -> syn::Type {
+ match &mut ty {
+ syn::Type::Path(p) => {
+ if let Some(ident) = p.path.get_ident() {
+ if let Some(newpath) = imports.get(ident) {
+ p.path = newpath.clone();
+ }
+ } else { unimplemented!(); }
+ },
+ syn::Type::Reference(r) => {
+ r.elem = Box::new(resolve_imported_refs(imports, (*r.elem).clone()));
+ },
+ syn::Type::Slice(s) => {
+ s.elem = Box::new(resolve_imported_refs(imports, (*s.elem).clone()));
+ },
+ syn::Type::Tuple(t) => {
+ for e in t.elems.iter_mut() {
+ *e = resolve_imported_refs(imports, e.clone());
+ }
+ },
+ _ => unimplemented!(),
+ }
+ ty
+}
+