Code Monkey home page Code Monkey logo

default_kwargs's Issues

use `Generics::split_for_impl`

let generics_of_default_args = self.sig.inputs_with_defaults.pairs().filter_map(|p| {
if self.sig.generics.params.pairs().any(|ty_par| {
*match ty_par.value() {
syn::GenericParam::Type(ty) => &ty.ident,
syn::GenericParam::Lifetime(lt) => &lt.lifetime.ident,
syn::GenericParam::Const(co) => &co.ident,
} == p.value().ty.to_token_stream().to_string()
}) {
Some(&p.value().ty)
} else {
None
}
});
let where_clause = &self.sig.generics.where_clause;
let generics_decl = generics_of_default_args.clone();
let strukt = quote! {
#[allow(unused)]
// #[allow(non_camel_case_types)]
#vis struct #struct_name <#(#generics_decl),*> #where_clause {
#vis #(#typed_fields),*
}
};
tokens.extend([strukt]);
let generics_decl = generics_of_default_args.clone();
let default_impl = quote! {
impl <#(#generics_decl),*>::core::default::Default for #struct_name <#(#generics_of_default_args),*> #where_clause {
fn default() -> Self {
Self {
#(#field_with_defaults),*
}
}
}
};
tokens.extend([default_impl]);

https://docs.rs/syn/latest/syn/struct.Generics.html#method.split_for_impl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.