X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Fmain.rs;h=b04d6b007828f9adc40eef56dae5bca551cc65b9;hb=c3d52f5f16d850662ab046a8eaf6cda9a3e40a72;hp=c0c5ecee1e9b0d4522d59c94658a52855b2051bf;hpb=0258057408ffd230bde23896b453ae54658c4ad3;p=rust-lightning diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index c0c5ecee1..b04d6b007 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -80,6 +80,19 @@ fn maybe_convert_trait_impl(w: &mut W, trait_path: &syn::Path } } +/// Write out the impl block for a defined trait struct which has a supertrait +fn do_write_impl_trait(w: &mut W, trait_path: &str, trait_name: &syn::Ident, for_obj: &str) { + match trait_path { + "util::events::MessageSendEventsProvider" => { + writeln!(w, "impl lightning::{} for {} {{", trait_path, for_obj).unwrap(); + writeln!(w, "\tfn get_and_clear_pending_msg_events(&self) -> Vec {{").unwrap(); + writeln!(w, "\t\t::get_and_clear_pending_msg_events(&self.{})", trait_path, trait_path, trait_name).unwrap(); + writeln!(w, "\t}}\n}}").unwrap(); + }, + _ => panic!(), + } +} + // ******************************* // *** Per-Type Printing Logic *** // ******************************* @@ -251,13 +264,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty writeln!(w, "\t}}\n}}").unwrap(); }, (s, i) => { - if s != "util::events::MessageSendEventsProvider" { unimplemented!(); } - // XXX: We straight-up cheat here - instead of bothering to get the trait object we - // just print what we need since this is only used in one place. - writeln!(w, "impl lightning::{} for {} {{", s, trait_name).unwrap(); - writeln!(w, "\tfn get_and_clear_pending_msg_events(&self) -> Vec {{").unwrap(); - writeln!(w, "\t\t::get_and_clear_pending_msg_events(&self.{})", s, s, i).unwrap(); - writeln!(w, "\t}}\n}}").unwrap(); + do_write_impl_trait(w, s, i, &trait_name); } ) );