Rebuild against current RL main
[ldk-c-bindings] / lightning-c-bindings / src / ln / features.rs
index 06dc42020a1d1509c2137e2a2c3b74d76e6ad693..1866068440f7fbdaf3558b09955c169ffe2fcd55 100644 (file)
@@ -35,6 +35,7 @@ pub(crate) extern "C" fn InitFeatures_clone_void(this_ptr: *const c_void) -> *mu
        Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInitFeatures)).clone() })) as *mut c_void
 }
 #[no_mangle]
+/// Creates a copy of the InitFeatures
 pub extern "C" fn InitFeatures_clone(orig: &InitFeatures) -> InitFeatures {
        orig.clone()
 }
@@ -53,6 +54,7 @@ pub(crate) extern "C" fn NodeFeatures_clone_void(this_ptr: *const c_void) -> *mu
        Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeFeatures)).clone() })) as *mut c_void
 }
 #[no_mangle]
+/// Creates a copy of the NodeFeatures
 pub extern "C" fn NodeFeatures_clone(orig: &NodeFeatures) -> NodeFeatures {
        orig.clone()
 }
@@ -71,9 +73,29 @@ pub(crate) extern "C" fn ChannelFeatures_clone_void(this_ptr: *const c_void) ->
        Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelFeatures)).clone() })) as *mut c_void
 }
 #[no_mangle]
+/// Creates a copy of the ChannelFeatures
 pub extern "C" fn ChannelFeatures_clone(orig: &ChannelFeatures) -> ChannelFeatures {
        orig.clone()
 }
+impl Clone for InvoiceFeatures {
+       fn clone(&self) -> Self {
+               Self {
+                       inner: if <*mut nativeInvoiceFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
+                               Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
+                       is_owned: true,
+               }
+       }
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn InvoiceFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
+       Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceFeatures)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the InvoiceFeatures
+pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures {
+       orig.clone()
+}
 
 use lightning::ln::features::InitFeatures as nativeInitFeaturesImport;
 type nativeInitFeatures = nativeInitFeaturesImport;
@@ -82,9 +104,15 @@ type nativeInitFeatures = nativeInitFeaturesImport;
 #[must_use]
 #[repr(C)]
 pub struct InitFeatures {
+       /// A pointer to the opaque Rust object.
+
        /// Nearly everywhere, inner must be non-null, however in places where
        /// the Rust equivalent takes an Option, it may be set to null to indicate None.
        pub inner: *mut nativeInitFeatures,
+       /// Indicates that this is the only struct which contains the same pointer.
+
+       /// Rust functions which take ownership of an object provided via an argument require
+       /// this to be true and invalidate the object pointed to by inner.
        pub is_owned: bool,
 }
 
@@ -95,8 +123,9 @@ impl Drop for InitFeatures {
                }
        }
 }
+/// Frees any resources used by the InitFeatures, if is_owned is set and inner is non-NULL.
 #[no_mangle]
-pub extern "C" fn InitFeatures_free(this_ptr: InitFeatures) { }
+pub extern "C" fn InitFeatures_free(this_obj: InitFeatures) { }
 #[allow(unused)]
 /// Used only if an object of this type is returned as a trait impl by a method
 extern "C" fn InitFeatures_free_void(this_ptr: *mut c_void) {
@@ -120,9 +149,15 @@ type nativeNodeFeatures = nativeNodeFeaturesImport;
 #[must_use]
 #[repr(C)]
 pub struct NodeFeatures {
+       /// A pointer to the opaque Rust object.
+
        /// Nearly everywhere, inner must be non-null, however in places where
        /// the Rust equivalent takes an Option, it may be set to null to indicate None.
        pub inner: *mut nativeNodeFeatures,
+       /// Indicates that this is the only struct which contains the same pointer.
+
+       /// Rust functions which take ownership of an object provided via an argument require
+       /// this to be true and invalidate the object pointed to by inner.
        pub is_owned: bool,
 }
 
@@ -133,8 +168,9 @@ impl Drop for NodeFeatures {
                }
        }
 }
+/// Frees any resources used by the NodeFeatures, if is_owned is set and inner is non-NULL.
 #[no_mangle]
-pub extern "C" fn NodeFeatures_free(this_ptr: NodeFeatures) { }
+pub extern "C" fn NodeFeatures_free(this_obj: NodeFeatures) { }
 #[allow(unused)]
 /// Used only if an object of this type is returned as a trait impl by a method
 extern "C" fn NodeFeatures_free_void(this_ptr: *mut c_void) {
@@ -158,9 +194,15 @@ type nativeChannelFeatures = nativeChannelFeaturesImport;
 #[must_use]
 #[repr(C)]
 pub struct ChannelFeatures {
+       /// A pointer to the opaque Rust object.
+
        /// Nearly everywhere, inner must be non-null, however in places where
        /// the Rust equivalent takes an Option, it may be set to null to indicate None.
        pub inner: *mut nativeChannelFeatures,
+       /// Indicates that this is the only struct which contains the same pointer.
+
+       /// Rust functions which take ownership of an object provided via an argument require
+       /// this to be true and invalidate the object pointed to by inner.
        pub is_owned: bool,
 }
 
@@ -171,8 +213,9 @@ impl Drop for ChannelFeatures {
                }
        }
 }
+/// Frees any resources used by the ChannelFeatures, if is_owned is set and inner is non-NULL.
 #[no_mangle]
-pub extern "C" fn ChannelFeatures_free(this_ptr: ChannelFeatures) { }
+pub extern "C" fn ChannelFeatures_free(this_obj: ChannelFeatures) { }
 #[allow(unused)]
 /// Used only if an object of this type is returned as a trait impl by a method
 extern "C" fn ChannelFeatures_free_void(this_ptr: *mut c_void) {
@@ -188,6 +231,51 @@ impl ChannelFeatures {
                ret
        }
 }
+
+use lightning::ln::features::InvoiceFeatures as nativeInvoiceFeaturesImport;
+type nativeInvoiceFeatures = nativeInvoiceFeaturesImport;
+
+/// Features used within an invoice.
+#[must_use]
+#[repr(C)]
+pub struct InvoiceFeatures {
+       /// A pointer to the opaque Rust object.
+
+       /// Nearly everywhere, inner must be non-null, however in places where
+       /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+       pub inner: *mut nativeInvoiceFeatures,
+       /// Indicates that this is the only struct which contains the same pointer.
+
+       /// Rust functions which take ownership of an object provided via an argument require
+       /// this to be true and invalidate the object pointed to by inner.
+       pub is_owned: bool,
+}
+
+impl Drop for InvoiceFeatures {
+       fn drop(&mut self) {
+               if self.is_owned && !<*mut nativeInvoiceFeatures>::is_null(self.inner) {
+                       let _ = unsafe { Box::from_raw(self.inner) };
+               }
+       }
+}
+/// Frees any resources used by the InvoiceFeatures, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn InvoiceFeatures_free(this_obj: InvoiceFeatures) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+extern "C" fn InvoiceFeatures_free_void(this_ptr: *mut c_void) {
+       unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceFeatures); }
+}
+#[allow(unused)]
+/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+impl InvoiceFeatures {
+       pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceFeatures {
+               assert!(self.is_owned);
+               let ret = self.inner;
+               self.inner = std::ptr::null_mut();
+               ret
+       }
+}
 /// Create a blank Features with no features set
 #[must_use]
 #[no_mangle]
@@ -242,7 +330,26 @@ pub extern "C" fn ChannelFeatures_known() -> ChannelFeatures {
        ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
 }
 
+/// Create a blank Features with no features set
+#[must_use]
+#[no_mangle]
+pub extern "C" fn InvoiceFeatures_empty() -> InvoiceFeatures {
+       let mut ret = lightning::ln::features::InvoiceFeatures::empty();
+       InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
+}
+
+/// Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`].
+///
+/// [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS
+#[must_use]
 #[no_mangle]
+pub extern "C" fn InvoiceFeatures_known() -> InvoiceFeatures {
+       let mut ret = lightning::ln::features::InvoiceFeatures::known();
+       InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
+}
+
+#[no_mangle]
+/// Serialize the InitFeatures object into a byte array which can be read by InitFeatures_read
 pub extern "C" fn InitFeatures_write(obj: &InitFeatures) -> crate::c_types::derived::CVec_u8Z {
        crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
 }
@@ -251,6 +358,7 @@ pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c
        crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) })
 }
 #[no_mangle]
+/// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read
 pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z {
        crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
 }
@@ -259,6 +367,7 @@ pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c
        crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) })
 }
 #[no_mangle]
+/// Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read
 pub extern "C" fn ChannelFeatures_write(obj: &ChannelFeatures) -> crate::c_types::derived::CVec_u8Z {
        crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
 }
@@ -267,20 +376,39 @@ pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate
        crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) })
 }
 #[no_mangle]
+/// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read
+pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z {
+       crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
+}
+#[no_mangle]
+pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+       crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) })
+}
+#[no_mangle]
+/// Read a InitFeatures from a byte array, created by InitFeatures_write
 pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ {
        let res = crate::c_types::deserialize_obj(ser);
        let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::features::InitFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
        local_res
 }
 #[no_mangle]
+/// Read a NodeFeatures from a byte array, created by NodeFeatures_write
 pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeFeaturesDecodeErrorZ {
        let res = crate::c_types::deserialize_obj(ser);
        let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::features::NodeFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
        local_res
 }
 #[no_mangle]
+/// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write
 pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ {
        let res = crate::c_types::deserialize_obj(ser);
        let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::features::ChannelFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
        local_res
 }
+#[no_mangle]
+/// Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write
+pub extern "C" fn InvoiceFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceFeaturesDecodeErrorZ {
+       let res = crate::c_types::deserialize_obj(ser);
+       let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::features::InvoiceFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
+       local_res
+}