]> git.bitcoin.ninja Git - ldk-c-bindings/blobdiff - lightning-c-bindings/src/lightning/ln/wire.rs
Add missing `rustc` `metadata` override for `lightning_types`
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / wire.rs
index a39f35e761ba878853bef49e26a4026e0e4815cb..e5747f69225e3a518db9f37ea562125abd7eec60 100644 (file)
@@ -12,6 +12,7 @@
 //! [BOLT #1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
 
 use alloc::str::FromStr;
 //! [BOLT #1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
 
 use alloc::str::FromStr;
+use alloc::string::String;
 use core::ffi::c_void;
 use core::convert::Infallible;
 use bitcoin::hashes::Hash;
 use core::ffi::c_void;
 use core::convert::Infallible;
 use bitcoin::hashes::Hash;
@@ -37,8 +38,8 @@ pub struct CustomMessageReader {
 }
 unsafe impl Send for CustomMessageReader {}
 unsafe impl Sync for CustomMessageReader {}
 }
 unsafe impl Send for CustomMessageReader {}
 unsafe impl Sync for CustomMessageReader {}
-#[no_mangle]
-pub(crate) extern "C" fn CustomMessageReader_clone_fields(orig: &CustomMessageReader) -> CustomMessageReader {
+#[allow(unused)]
+pub(crate) fn CustomMessageReader_clone_fields(orig: &CustomMessageReader) -> CustomMessageReader {
        CustomMessageReader {
                this_arg: orig.this_arg,
                read: Clone::clone(&orig.read),
        CustomMessageReader {
                this_arg: orig.this_arg,
                read: Clone::clone(&orig.read),
@@ -56,12 +57,27 @@ impl rustCustomMessageReader for CustomMessageReader {
        }
 }
 
        }
 }
 
+pub struct CustomMessageReaderRef(CustomMessageReader);
+impl rustCustomMessageReader for CustomMessageReaderRef {
+       type CustomMessage = crate::lightning::ln::wire::Type;
+       fn read<R:crate::c_types::io::Read>(&self, mut message_type: u16, mut buffer: &mut R) -> Result<Option<crate::lightning::ln::wire::Type>, lightning::ln::msgs::DecodeError> {
+               let mut ret = (self.0.read)(self.0.this_arg, message_type, crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec(buffer)));
+               let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = { /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ let ret_0_opt = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }); if ret_0_opt.is_none() { None } else { Some({ { { ret_0_opt.take() } }})} }; local_ret_0 }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
+               local_ret
+       }
+}
+
 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
 // directly as a Deref trait in higher-level structs:
 impl core::ops::Deref for CustomMessageReader {
 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
 // directly as a Deref trait in higher-level structs:
 impl core::ops::Deref for CustomMessageReader {
-       type Target = Self;
-       fn deref(&self) -> &Self {
-               self
+       type Target = CustomMessageReaderRef;
+       fn deref(&self) -> &Self::Target {
+               unsafe { &*(self as *const _ as *const CustomMessageReaderRef) }
+       }
+}
+impl core::ops::DerefMut for CustomMessageReader {
+       fn deref_mut(&mut self) -> &mut CustomMessageReaderRef {
+               unsafe { &mut *(self as *mut _ as *mut CustomMessageReaderRef) }
        }
 }
 /// Calls the free function if one is set
        }
 }
 /// Calls the free function if one is set
@@ -77,6 +93,7 @@ impl Drop for CustomMessageReader {
 mod encode {
 
 use alloc::str::FromStr;
 mod encode {
 
 use alloc::str::FromStr;
+use alloc::string::String;
 use core::ffi::c_void;
 use core::convert::Infallible;
 use bitcoin::hashes::Hash;
 use core::ffi::c_void;
 use core::convert::Infallible;
 use bitcoin::hashes::Hash;
@@ -99,19 +116,24 @@ pub struct Type {
        pub debug_str: extern "C" fn (this_arg: *const c_void) -> crate::c_types::Str,
        /// Serialize the object into a byte array
        pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
        pub debug_str: extern "C" fn (this_arg: *const c_void) -> crate::c_types::Str,
        /// Serialize the object into a byte array
        pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
+       /// Called, if set, after this Type has been cloned into a duplicate object.
+       /// The new Type is provided, and should be mutated as needed to perform a
+       /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
+       pub cloned: Option<extern "C" fn (new_Type: &mut Type)>,
        /// Frees any resources associated with this object given its this_arg pointer.
        /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
        pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
 }
 unsafe impl Send for Type {}
 unsafe impl Sync for Type {}
        /// Frees any resources associated with this object given its this_arg pointer.
        /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
        pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
 }
 unsafe impl Send for Type {}
 unsafe impl Sync for Type {}
-#[no_mangle]
-pub(crate) extern "C" fn Type_clone_fields(orig: &Type) -> Type {
+#[allow(unused)]
+pub(crate) fn Type_clone_fields(orig: &Type) -> Type {
        Type {
                this_arg: orig.this_arg,
                type_id: Clone::clone(&orig.type_id),
                debug_str: Clone::clone(&orig.debug_str),
                write: Clone::clone(&orig.write),
        Type {
                this_arg: orig.this_arg,
                type_id: Clone::clone(&orig.type_id),
                debug_str: Clone::clone(&orig.debug_str),
                write: Clone::clone(&orig.write),
+               cloned: Clone::clone(&orig.cloned),
                free: Clone::clone(&orig.free),
        }
 }
                free: Clone::clone(&orig.free),
        }
 }
@@ -120,12 +142,40 @@ impl core::fmt::Debug for Type {
                f.write_str((self.debug_str)(self.this_arg).into_str())
        }
 }
                f.write_str((self.debug_str)(self.this_arg).into_str())
        }
 }
+impl core::fmt::Debug for TypeRef {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+               f.write_str((self.0.debug_str)(self.0.this_arg).into_str())
+       }
+}
 impl lightning::util::ser::Writeable for Type {
        fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
                let vec = (self.write)(self.this_arg);
                w.write_all(vec.as_slice())
        }
 }
 impl lightning::util::ser::Writeable for Type {
        fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
                let vec = (self.write)(self.this_arg);
                w.write_all(vec.as_slice())
        }
 }
+impl lightning::util::ser::Writeable for TypeRef {
+       fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
+               let vec = (self.0.write)(self.0.this_arg);
+               w.write_all(vec.as_slice())
+       }
+}
+#[no_mangle]
+/// Creates a copy of a Type
+pub extern "C" fn Type_clone(orig: &Type) -> Type {
+       let mut res = Type_clone_fields(orig);
+       if let Some(f) = orig.cloned { (f)(&mut res) };
+       res
+}
+impl Clone for Type {
+       fn clone(&self) -> Self {
+               Type_clone(self)
+       }
+}
+impl Clone for TypeRef {
+       fn clone(&self) -> Self {
+               Self(Type_clone(&self.0))
+       }
+}
 
 use lightning::ln::wire::Type as rustType;
 impl rustType for Type {
 
 use lightning::ln::wire::Type as rustType;
 impl rustType for Type {
@@ -135,12 +185,25 @@ impl rustType for Type {
        }
 }
 
        }
 }
 
+pub struct TypeRef(Type);
+impl rustType for TypeRef {
+       fn type_id(&self) -> u16 {
+               let mut ret = (self.0.type_id)(self.0.this_arg);
+               ret
+       }
+}
+
 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
 // directly as a Deref trait in higher-level structs:
 impl core::ops::Deref for Type {
 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
 // directly as a Deref trait in higher-level structs:
 impl core::ops::Deref for Type {
-       type Target = Self;
-       fn deref(&self) -> &Self {
-               self
+       type Target = TypeRef;
+       fn deref(&self) -> &Self::Target {
+               unsafe { &*(self as *const _ as *const TypeRef) }
+       }
+}
+impl core::ops::DerefMut for Type {
+       fn deref_mut(&mut self) -> &mut TypeRef {
+               unsafe { &mut *(self as *mut _ as *mut TypeRef) }
        }
 }
 /// Calls the free function if one is set
        }
 }
 /// Calls the free function if one is set