Skip to content

Commit

Permalink
Support default SlotFragment implmentations
Browse files Browse the repository at this point in the history
  • Loading branch information
jovenlin0527 committed Nov 23, 2021
1 parent bc0161b commit 94c23e4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pyo3-macros-backend/src/pyimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ pub fn gen_default_slot_impls(cls: &syn::Ident, method_defs: Vec<TokenStream>) -
.collect();

let mut proto_impls = Vec::new();
let mut trait_impls = Vec::new();

let mut implemented_proto_fragments = HashSet::new();

for meth in &mut method_defs {
let options = PyFunctionOptions::from_attrs(&mut meth.attrs).unwrap();
Expand All @@ -158,15 +161,19 @@ pub fn gen_default_slot_impls(cls: &syn::Ident, method_defs: Vec<TokenStream>) -
let attrs = get_cfg_attributes(&meth.attrs);
proto_impls.push(quote!(#(#attrs)* #token_stream))
}
GeneratedPyMethod::SlotTraitImpl(..) => {
todo!()
GeneratedPyMethod::SlotTraitImpl(method_name, token_stream) => {
implemented_proto_fragments.insert(method_name);
let attrs = get_cfg_attributes(&meth.attrs);
trait_impls.push(quote!(#(#attrs)* #token_stream));
}
GeneratedPyMethod::Method(_) | GeneratedPyMethod::TraitImpl(_) => {
panic!("Only protocol methods can have default implementation!")
}
}
}

add_shared_proto_slots(&ty, &mut proto_impls, implemented_proto_fragments);

quote! {
impl #cls {
#(#method_defs)*
Expand Down

0 comments on commit 94c23e4

Please sign in to comment.