Skip to content

Commit ac078c1

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 56134a2 commit ac078c1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-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)));
@@ -706,6 +706,11 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
706706
///
707707
/// A few non-crate Traits are hard-coded including Default.
708708
fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut TypeResolver) {
709+
match export_status(&i.attrs) {
710+
ExportStatus::Export => {},
711+
ExportStatus::NoExport|ExportStatus::TestOnly => return,
712+
}
713+
709714
if let syn::Type::Tuple(_) = &*i.self_ty {
710715
if types.understood_c_type(&*i.self_ty, None) {
711716
let mut gen_types = GenericTypes::new();
@@ -952,10 +957,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
952957
},
953958
"PartialEq" => {},
954959
// If we have no generics, try a manual implementation:
955-
_ if p.path.get_ident().is_some() => maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types),
956-
_ => {},
960+
_ => maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types),
957961
}
958-
} else if p.path.get_ident().is_some() {
962+
} else {
959963
// If we have no generics, try a manual implementation:
960964
maybe_convert_trait_impl(w, &trait_path.1, &*i.self_ty, types, &gen_types);
961965
}

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ impl PartialEq for CommitmentTransaction {
843843
}
844844
}
845845

846+
/// (C-not exported) as users never need to call this directly
846847
impl Writeable for Vec<HTLCOutputInCommitment> {
847848
#[inline]
848849
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
@@ -854,6 +855,7 @@ impl Writeable for Vec<HTLCOutputInCommitment> {
854855
}
855856
}
856857

858+
/// (C-not exported) as users never need to call this directly
857859
impl Readable for Vec<HTLCOutputInCommitment> {
858860
#[inline]
859861
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {

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)