]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[bindings] Don't require trait impl for-structs to have no generics
authorMatt Corallo <git@bluematt.me>
Thu, 31 Dec 2020 16:14:22 +0000 (11:14 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 15 Jan 2021 00:49:14 +0000 (19:49 -0500)
This (finally) exposes `ChannelManager`/`ChannelMonitor` _write
methods, which were (needlessly) excluded as the structs themselves
have generic parameters. Sadly, we also now need to parse
`(C-not exported)` doc comments on impl blocks as we otherwise try
to expose _write methods for `&Vec<RouteHop>`, which doesn't work
(and isn't particularly interesting for users anyway). We add such
doc comments there.

c-bindings-gen/src/main.rs
lightning/src/ln/chan_utils.rs
lightning/src/routing/router.rs

index 9bedbf577a7d43901e1c1a23e256e7db4b719b9c..9f86579a748c63ac8522e5149ee183806dd8487d 100644 (file)
@@ -65,7 +65,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
                let full_obj_path;
                let mut has_inner = false;
                if let syn::Type::Path(ref p) = for_ty {
-                       if let Some(ident) = p.path.get_ident() {
+                       if let Some(ident) = single_ident_generic_path_to_ident(&p.path) {
                                for_obj = format!("{}", ident);
                                full_obj_path = for_obj.clone();
                                has_inner = types.c_type_has_inner_from_path(&types.resolve_path(&p.path, Some(generics)));
@@ -706,6 +706,11 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
 ///
 /// A few non-crate Traits are hard-coded including Default.
 fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut TypeResolver) {
+       match export_status(&i.attrs) {
+               ExportStatus::Export => {},
+               ExportStatus::NoExport|ExportStatus::TestOnly => return,
+       }
+
        if let syn::Type::Tuple(_) = &*i.self_ty {
                if types.understood_c_type(&*i.self_ty, None) {
                        let mut gen_types = GenericTypes::new();
@@ -951,10 +956,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
                                                        },
                                                        "PartialEq" => {},
                                                        // If we have no generics, try a manual implementation:
-                                                       _ if p.path.get_ident().is_some() => maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types),
-                                                       _ => {},
+                                                       _ => maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types),
                                                }
-                                       } else if p.path.get_ident().is_some() {
+                                       } else {
                                                // If we have no generics, try a manual implementation:
                                                maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types);
                                        }
index 2ccee7b2d521a8460b20e643355a99bff0d0632e..b1171f543989c8d9deb7c6d68a18fb61e5e27af5 100644 (file)
@@ -843,6 +843,7 @@ impl PartialEq for CommitmentTransaction {
        }
 }
 
+/// (C-not exported) as users never need to call this directly
 impl Writeable for Vec<HTLCOutputInCommitment> {
        #[inline]
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
@@ -854,6 +855,7 @@ impl Writeable for Vec<HTLCOutputInCommitment> {
        }
 }
 
+/// (C-not exported) as users never need to call this directly
 impl Readable for Vec<HTLCOutputInCommitment> {
        #[inline]
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
index f73a9a501bfbb75cf3bbafcb3f2193093bfba969..32084fad581ad55e232d997584251af168a853bc 100644 (file)
@@ -45,6 +45,7 @@ pub struct RouteHop {
        pub cltv_expiry_delta: u32,
 }
 
+/// (C-not exported)
 impl Writeable for Vec<RouteHop> {
        fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
                (self.len() as u8).write(writer)?;
@@ -60,6 +61,7 @@ impl Writeable for Vec<RouteHop> {
        }
 }
 
+/// (C-not exported)
 impl Readable for Vec<RouteHop> {
        fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Vec<RouteHop>, DecodeError> {
                let hops_count: u8 = Readable::read(reader)?;