/// Prints concrete generic parameters for a struct/trait/function, including the less-than and
/// greater-than symbols, if any generic parameters are defined.
pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool) {
- maybe_write_generics_intern(w, generics, generics_impld, types, concrete_lifetimes, false);
+ maybe_write_generics_intern(w, generics, Some(generics_impld), types, concrete_lifetimes, false);
}
pub fn maybe_write_non_lifetime_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver) {
- maybe_write_generics_intern(w, generics, generics_impld, types, false, true);
+ maybe_write_generics_intern(w, generics, Some(generics_impld), types, false, true);
}
-fn maybe_write_generics_intern<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool, dummy_lifetimes: bool) {
+pub fn maybe_write_type_non_lifetime_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, types: &TypeResolver) {
+ maybe_write_generics_intern(w, generics, None, types, false, true);
+}
+
+fn maybe_write_generics_intern<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: Option<&syn::PathArguments>, types: &TypeResolver, concrete_lifetimes: bool, dummy_lifetimes: bool) {
let mut gen_types = GenericTypes::new(None);
assert!(gen_types.learn_generics(generics, types));
if generics.params.is_empty() { return; }
if types.understood_c_type(&syn::parse_quote!(#type_ident), Some(&gen_types)) {
types.write_c_type_in_generic_param(&mut out, &syn::parse_quote!(#type_ident), Some(&gen_types), false);
} else {
- if let syn::PathArguments::AngleBracketed(args) = generics_impld {
+ if let Some(syn::PathArguments::AngleBracketed(args)) = generics_impld {
if let syn::GenericArgument::Type(ty) = &args.args[idx] {
types.write_c_type_in_generic_param(&mut out, &ty, Some(&gen_types), false);
}
}
}
- let mut t_gen_args = String::new();
- for (idx, _) in $trait.generics.params.iter().enumerate() {
- if idx != 0 { t_gen_args += ", " };
- t_gen_args += "_"
- }
- // rustc doesn't like <_> if the _ is actually a lifetime, so
- // if all the parameters are lifetimes just skip it.
- let mut nonlifetime_param = false;
- for param in $trait.generics.params.iter() {
- if let syn::GenericParam::Lifetime(_) = param {}
- else { nonlifetime_param = true; }
- }
- if !nonlifetime_param { t_gen_args = String::new(); }
+ let mut t_gen_args_vec = Vec::new();
+ maybe_write_type_non_lifetime_generics(&mut t_gen_args_vec, &$trait.generics, &trait_resolver);
+ let t_gen_args = String::from_utf8(t_gen_args_vec).unwrap();
if takes_self {
- write!(w, "<native{} as {}<{}>>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap();
+ write!(w, "<native{} as {}{}>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap();
} else {
- write!(w, "<native{} as {}<{}>>::{}(", ident, $trait_path, t_gen_args, $m.sig.ident).unwrap();
+ write!(w, "<native{} as {}{}>::{}(", ident, $trait_path, t_gen_args, $m.sig.ident).unwrap();
}
let mut real_type = "".to_string();