Update auto-generated bindings to 0.0.113
[ldk-c-bindings] / lightning-c-bindings / src / lightning / util / string.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 //! Utilities for strings.
10
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
18
19
20 use lightning::util::string::PrintableString as nativePrintableStringImport;
21 pub(crate) type nativePrintableString = nativePrintableStringImport<'static>;
22
23 /// A string that displays only printable characters, replacing control characters with
24 /// [`core::char::REPLACEMENT_CHARACTER`].
25 #[must_use]
26 #[repr(C)]
27 pub struct PrintableString {
28         /// A pointer to the opaque Rust object.
29
30         /// Nearly everywhere, inner must be non-null, however in places where
31         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
32         pub inner: *mut nativePrintableString,
33         /// Indicates that this is the only struct which contains the same pointer.
34
35         /// Rust functions which take ownership of an object provided via an argument require
36         /// this to be true and invalidate the object pointed to by inner.
37         pub is_owned: bool,
38 }
39
40 impl Drop for PrintableString {
41         fn drop(&mut self) {
42                 if self.is_owned && !<*mut nativePrintableString>::is_null(self.inner) {
43                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
44                 }
45         }
46 }
47 /// Frees any resources used by the PrintableString, if is_owned is set and inner is non-NULL.
48 #[no_mangle]
49 pub extern "C" fn PrintableString_free(this_obj: PrintableString) { }
50 #[allow(unused)]
51 /// Used only if an object of this type is returned as a trait impl by a method
52 pub(crate) extern "C" fn PrintableString_free_void(this_ptr: *mut c_void) {
53         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrintableString) };
54 }
55 #[allow(unused)]
56 impl PrintableString {
57         pub(crate) fn get_native_ref(&self) -> &'static nativePrintableString {
58                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
59         }
60         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrintableString {
61                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
62         }
63         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
64         pub(crate) fn take_inner(mut self) -> *mut nativePrintableString {
65                 assert!(self.is_owned);
66                 let ret = ObjOps::untweak_ptr(self.inner);
67                 self.inner = core::ptr::null_mut();
68                 ret
69         }
70 }
71 #[no_mangle]
72 pub extern "C" fn PrintableString_get_a(this_ptr: &PrintableString) -> crate::c_types::Str {
73         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
74         inner_val.into()
75 }
76 #[no_mangle]
77 pub extern "C" fn PrintableString_set_a(this_ptr: &mut PrintableString, mut val: crate::c_types::Str) {
78         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_str();
79 }
80 /// Constructs a new PrintableString given each field
81 #[must_use]
82 #[no_mangle]
83 pub extern "C" fn PrintableString_new(mut a_arg: crate::c_types::Str) -> PrintableString {
84         PrintableString { inner: ObjOps::heap_alloc(lightning::util::string::PrintableString (
85                 a_arg.into_str(),
86         )), is_owned: true }
87 }