}
}
-
+pub fn maybe_write_lifetime_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, types: &TypeResolver) {
+ let mut gen_types = GenericTypes::new(None);
+ assert!(gen_types.learn_generics(generics, types));
+ if generics.params.iter().any(|param| if let syn::GenericParam::Lifetime(_) = param { true } else { false }) {
+ write!(w, "<").unwrap();
+ for (idx, generic) in generics.params.iter().enumerate() {
+ match generic {
+ syn::GenericParam::Type(_) => {},
+ syn::GenericParam::Lifetime(lt) => {
+ write!(w, "{}'{}", if idx != 0 { ", " } else { "" }, lt.lifetime.ident).unwrap();
+ },
+ _ => unimplemented!(),
+ }
+ }
+ write!(w, ">").unwrap();
+ }
+}
// Finally, implement the original Rust trait for the newly created mapped trait.
writeln!(w, "\nuse {}::{} as rust{};", types.module_path, t.ident, trait_name).unwrap();
if implementable {
- write!(w, "impl rust{}", t.ident).unwrap();
+ write!(w, "impl").unwrap();
+ maybe_write_lifetime_generics(w, &t.generics, types);
+ write!(w, " rust{}", t.ident).unwrap();
maybe_write_generics(w, &t.generics, types, false);
writeln!(w, " for {} {{", trait_name).unwrap();
impl_trait_for_c!(t, "", types);