Update C/C++ demo tests with latest 0.0.121 API changes
[ldk-c-bindings] / lightning-c-bindings / src / lightning_rapid_gossip_sync / error.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 /// Error types that these functions can return
10
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20 /// All-encompassing standard error type that processing can return
21 #[derive(Clone)]
22 #[must_use]
23 #[repr(C)]
24 pub enum GraphSyncError {
25         /// Error trying to read the update data, typically due to an erroneous data length indication
26         /// that is greater than the actual amount of data provided
27         DecodeError(
28                 crate::lightning::ln::msgs::DecodeError),
29         /// Error applying the patch to the network graph, usually the result of updates that are too
30         /// old or missing prerequisite data to the application of updates out of order
31         LightningError(
32                 crate::lightning::ln::msgs::LightningError),
33 }
34 use lightning_rapid_gossip_sync::error::GraphSyncError as GraphSyncErrorImport;
35 pub(crate) type nativeGraphSyncError = GraphSyncErrorImport;
36
37 impl GraphSyncError {
38         #[allow(unused)]
39         pub(crate) fn to_native(&self) -> nativeGraphSyncError {
40                 match self {
41                         GraphSyncError::DecodeError (ref a, ) => {
42                                 let mut a_nonref = Clone::clone(a);
43                                 nativeGraphSyncError::DecodeError (
44                                         a_nonref.into_native(),
45                                 )
46                         },
47                         GraphSyncError::LightningError (ref a, ) => {
48                                 let mut a_nonref = Clone::clone(a);
49                                 nativeGraphSyncError::LightningError (
50                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
51                                 )
52                         },
53                 }
54         }
55         #[allow(unused)]
56         pub(crate) fn into_native(self) -> nativeGraphSyncError {
57                 match self {
58                         GraphSyncError::DecodeError (mut a, ) => {
59                                 nativeGraphSyncError::DecodeError (
60                                         a.into_native(),
61                                 )
62                         },
63                         GraphSyncError::LightningError (mut a, ) => {
64                                 nativeGraphSyncError::LightningError (
65                                         *unsafe { Box::from_raw(a.take_inner()) },
66                                 )
67                         },
68                 }
69         }
70         #[allow(unused)]
71         pub(crate) fn from_native(native: &nativeGraphSyncError) -> Self {
72                 match native {
73                         nativeGraphSyncError::DecodeError (ref a, ) => {
74                                 let mut a_nonref = Clone::clone(a);
75                                 GraphSyncError::DecodeError (
76                                         crate::lightning::ln::msgs::DecodeError::native_into(a_nonref),
77                                 )
78                         },
79                         nativeGraphSyncError::LightningError (ref a, ) => {
80                                 let mut a_nonref = Clone::clone(a);
81                                 GraphSyncError::LightningError (
82                                         crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
83                                 )
84                         },
85                 }
86         }
87         #[allow(unused)]
88         pub(crate) fn native_into(native: nativeGraphSyncError) -> Self {
89                 match native {
90                         nativeGraphSyncError::DecodeError (mut a, ) => {
91                                 GraphSyncError::DecodeError (
92                                         crate::lightning::ln::msgs::DecodeError::native_into(a),
93                                 )
94                         },
95                         nativeGraphSyncError::LightningError (mut a, ) => {
96                                 GraphSyncError::LightningError (
97                                         crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a), is_owned: true },
98                                 )
99                         },
100                 }
101         }
102 }
103 /// Frees any resources used by the GraphSyncError
104 #[no_mangle]
105 pub extern "C" fn GraphSyncError_free(this_ptr: GraphSyncError) { }
106 /// Creates a copy of the GraphSyncError
107 #[no_mangle]
108 pub extern "C" fn GraphSyncError_clone(orig: &GraphSyncError) -> GraphSyncError {
109         orig.clone()
110 }
111 #[allow(unused)]
112 /// Used only if an object of this type is returned as a trait impl by a method
113 pub(crate) extern "C" fn GraphSyncError_clone_void(this_ptr: *const c_void) -> *mut c_void {
114         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const GraphSyncError)).clone() })) as *mut c_void
115 }
116 #[allow(unused)]
117 /// Used only if an object of this type is returned as a trait impl by a method
118 pub(crate) extern "C" fn GraphSyncError_free_void(this_ptr: *mut c_void) {
119         let _ = unsafe { Box::from_raw(this_ptr as *mut GraphSyncError) };
120 }
121 #[no_mangle]
122 /// Utility method to constructs a new DecodeError-variant GraphSyncError
123 pub extern "C" fn GraphSyncError_decode_error(a: crate::lightning::ln::msgs::DecodeError) -> GraphSyncError {
124         GraphSyncError::DecodeError(a, )
125 }
126 #[no_mangle]
127 /// Utility method to constructs a new LightningError-variant GraphSyncError
128 pub extern "C" fn GraphSyncError_lightning_error(a: crate::lightning::ln::msgs::LightningError) -> GraphSyncError {
129         GraphSyncError::LightningError(a, )
130 }