Drop `#[no_mangle]`/`extern` flag for internal-only method
[ldk-c-bindings] / c-bindings-gen / src / main.rs
index ad2690ce8a0ff99ac6695b18ac0607451f143ead..956420be780a938e817d856392f928b443695257 100644 (file)
@@ -36,6 +36,7 @@ use blocks::*;
 
 const DEFAULT_IMPORTS: &'static str = "
 use alloc::str::FromStr;
+use alloc::string::String;
 use core::ffi::c_void;
 use core::convert::Infallible;
 use bitcoin::hashes::Hash;
@@ -533,8 +534,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                                                                        writeln!(w, "\ttype {} = crate::{};", t.ident, $type_resolver.resolve_path(&tr.path, Some(&gen_types))).unwrap();
                                                                        for bound in bounds_iter {
                                                                                if let syn::TypeParamBound::Trait(t) = bound {
-                                                                                       // We only allow for `?Sized` here.
-                                                                                       if let syn::TraitBoundModifier::Maybe(_) = t.modifier {} else { panic!(); }
+                                                                                       // We only allow for `Sized` here.
                                                                                        assert_eq!(t.path.segments.len(), 1);
                                                                                        assert_eq!(format!("{}", t.path.segments[0].ident), "Sized");
                                                                                }
@@ -554,8 +554,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
        writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap();
        writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap();
 
-       writeln!(w, "#[no_mangle]").unwrap();
-       writeln!(w, "pub(crate) extern \"C\" fn {}_clone_fields(orig: &{}) -> {} {{", trait_name, trait_name, trait_name).unwrap();
+       writeln!(w, "pub(crate) fn {}_clone_fields(orig: &{}) -> {} {{", trait_name, trait_name, trait_name).unwrap();
        writeln!(w, "\t{} {{", trait_name).unwrap();
        writeln!(w, "\t\tthis_arg: orig.this_arg,").unwrap();
        for (field, clone_fn, _) in generated_fields.iter() {
@@ -647,6 +646,8 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
                writeln!(w, "// directly as a Deref trait in higher-level structs:").unwrap();
                writeln!(w, "impl core::ops::Deref for {} {{\n\ttype Target = Self;", trait_name).unwrap();
                writeln!(w, "\tfn deref(&self) -> &Self {{\n\t\tself\n\t}}\n}}").unwrap();
+               writeln!(w, "impl core::ops::DerefMut for {} {{", trait_name).unwrap();
+               writeln!(w, "\tfn deref_mut(&mut self) -> &mut Self {{\n\t\tself\n\t}}\n}}").unwrap();
        }
 
        writeln!(w, "/// Calls the free function if one is set").unwrap();