Skip to content

Commit 9630d52

Browse files
committed
[bindings] Don't require trait impl for-structs to have no generics
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.
1 parent 7eb2b4d commit 9630d52

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

c-bindings-gen/src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
6565
let full_obj_path;
6666
let mut has_inner = false;
6767
if let syn::Type::Path(ref p) = for_ty {
68-
if let Some(ident) = p.path.get_ident() {
68+
if let Some(ident) = single_ident_generic_path_to_ident(&p.path) {
6969
for_obj = format!("{}", ident);
7070
full_obj_path = for_obj.clone();
7171
has_inner = types.c_type_has_inner_from_path(&types.resolve_path(&p.path, Some(generics)));
@@ -701,6 +701,11 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
701701
///
702702
/// A few non-crate Traits are hard-coded including Default.
703703
fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut TypeResolver) {
704+
match export_status(&i.attrs) {
705+
ExportStatus::Export => {},
706+
ExportStatus::NoExport|ExportStatus::TestOnly => return,
707+
}
708+
704709
if let syn::Type::Tuple(_) = &*i.self_ty {
705710
if types.understood_c_type(&*i.self_ty, None) {
706711
let mut gen_types = GenericTypes::new();
@@ -946,10 +951,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
946951
},
947952
"PartialEq" => {},
948953
// If we have no generics, try a manual implementation:
949-
_ if p.path.get_ident().is_some() => maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types),
950-
_ => {},
954+
_ => maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types),
951955
}
952-
} else if p.path.get_ident().is_some() {
956+
} else {
953957
// If we have no generics, try a manual implementation:
954958
maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types);
955959
}

lightning/src/routing/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct RouteHop {
4545
pub cltv_expiry_delta: u32,
4646
}
4747

48+
/// (C-not exported)
4849
impl Writeable for Vec<RouteHop> {
4950
fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
5051
(self.len() as u8).write(writer)?;
@@ -60,6 +61,7 @@ impl Writeable for Vec<RouteHop> {
6061
}
6162
}
6263

64+
/// (C-not exported)
6365
impl Readable for Vec<RouteHop> {
6466
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Vec<RouteHop>, DecodeError> {
6567
let hops_count: u8 = Readable::read(reader)?;

0 commit comments

Comments
 (0)