X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Ferrors.rs;h=884c942b5016c357d29ffeef588de689d5c509b0;hb=0ac4dbdb8352c898100b34f0ef8ed9cebfea7786;hp=43755de8084e6489768986d3764b665a69663e9c;hpb=3e46e1794f14640e35f09cc6da4169c152de34ce;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/util/errors.rs b/lightning-c-bindings/src/lightning/util/errors.rs index 43755de..884c942 100644 --- a/lightning-c-bindings/src/lightning/util/errors.rs +++ b/lightning-c-bindings/src/lightning/util/errors.rs @@ -148,7 +148,8 @@ impl APIError { } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeAPIError) -> Self { + pub(crate) fn from_native(native: &APIErrorImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeAPIError) }; match native { nativeAPIError::APIMisuseError {ref err, } => { let mut err_nonref = Clone::clone(err); @@ -226,6 +227,16 @@ pub extern "C" fn APIError_free(this_ptr: APIError) { } pub extern "C" fn APIError_clone(orig: &APIError) -> APIError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn APIError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const APIError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn APIError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut APIError) }; +} #[no_mangle] /// Utility method to constructs a new APIMisuseError-variant APIError pub extern "C" fn APIError_apimisuse_error(err: crate::c_types::Str) -> APIError { @@ -272,11 +283,18 @@ pub extern "C" fn APIError_incompatible_shutdown_script(script: crate::lightning pub extern "C" fn APIError_eq(a: &APIError, b: &APIError) -> bool { if &a.to_native() == &b.to_native() { true } else { false } } +/// Get a string which allows debug introspection of a APIError object +pub extern "C" fn APIError_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::errors::APIError }).into()} #[no_mangle] /// Serialize the APIError object into a byte array which can be read by APIError_read pub extern "C" fn APIError_write(obj: &crate::lightning::util::errors::APIError) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn APIError_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + APIError_write(unsafe { &*(obj as *const APIError) }) +} #[no_mangle] /// Read a APIError from a byte array, created by APIError_write pub extern "C" fn APIError_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_APIErrorZDecodeErrorZ {