Support no_std on the generated crate
[ldk-c-bindings] / lightning-c-bindings / src / c_types / mod.rs
index 9e928a6065922e87409de08506ddf04e26e945a4..0bd976bac8f1e47ee75ad5995a0bf123ce8f01dd 100644 (file)
@@ -20,6 +20,8 @@ use core::ffi::c_void;
 pub(crate) use std::io::{self, Cursor, Read};
 #[cfg(feature = "no-std")]
 pub(crate) use core2::io::{self, Cursor, Read};
+#[cfg(feature = "no-std")]
+use alloc::{boxed::Box, vec::Vec, string::String};
 
 #[repr(C)]
 /// A dummy struct of which an instance must never exist.
@@ -192,6 +194,7 @@ pub enum IOError {
        Other,
        UnexpectedEof,
 }
+#[cfg(feature = "std")]
 impl IOError {
        pub(crate) fn from_rust(err: std::io::Error) -> Self {
                match err.kind() {
@@ -576,6 +579,9 @@ impl<T> TakePointer<*mut T> for *mut T {
 
 
 pub(crate) mod ObjOps {
+       #[cfg(feature = "no-std")]
+       use alloc::boxed::Box;
+
        #[inline]
        #[must_use = "returns new dangling pointer"]
        pub(crate) fn heap_alloc<T>(obj: T) -> *mut T {