+/// Convert "TraitA : TraitB" to a single function name and return type.
+///
+/// This is (obviously) somewhat over-specialized and only useful for TraitB's that only require a
+/// single function (eg for serialization).
+fn convert_trait_impl_field(trait_path: &str) -> (String, &'static str) {
+ match trait_path {
+ "util::ser::Writeable" => ("write".to_owned(), "crate::c_types::derived::CVec_u8Z"),
+ _ => unimplemented!(),
+ }
+}
+
+/// Companion to convert_trait_impl_field, write an assignment for the function defined by it for
+/// `for_obj` which implements the the trait at `trait_path`.
+fn write_trait_impl_field_assign<W: std::io::Write>(w: &mut W, trait_path: &str, for_obj: &syn::Ident) {
+ match trait_path {
+ "util::ser::Writeable" => {
+ writeln!(w, "\t\twrite: {}_write_void,", for_obj).unwrap();
+ },
+ _ => unimplemented!(),
+ }
+}
+
+/// Write out the impl block for a defined trait struct which has a supertrait
+fn do_write_impl_trait<W: std::io::Write>(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<lightning::util::events::MessageSendEvent> {{").unwrap();
+ writeln!(w, "\t\t<crate::{} as lightning::{}>::get_and_clear_pending_msg_events(&self.{})", trait_path, trait_path, trait_name).unwrap();
+ writeln!(w, "\t}}\n}}").unwrap();
+ },
+ "util::ser::Writeable" => {
+ writeln!(w, "impl lightning::{} for {} {{", trait_path, for_obj).unwrap();
+ writeln!(w, "\tfn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {{").unwrap();
+ writeln!(w, "\t\tlet vec = (self.write)(self.this_arg);").unwrap();
+ writeln!(w, "\t\tw.write_all(vec.as_slice())").unwrap();
+ writeln!(w, "\t}}\n}}").unwrap();
+ },
+ _ => panic!(),
+ }
+}
+