From: Matt Corallo Date: Wed, 14 Apr 2021 02:58:32 +0000 (-0400) Subject: Implement conversion of std::io::Error to Rust X-Git-Tag: v0.0.98~4^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=47b7d6e36914774534f4a80315c8d38e0424a2db;p=ldk-c-bindings Implement conversion of std::io::Error to Rust --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index bd0c9c5..6ea8e28 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -950,6 +950,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "str" if is_ref => Some(""), "alloc::string::String"|"String" => Some(""), + "std::io::Error" if !is_ref => Some(""), // Note that we'll panic for String if is_ref, as we only have non-owned memory, we // cannot create a &String. @@ -1016,6 +1017,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "str" if is_ref => Some(".into_str()"), "alloc::string::String"|"String" => Some(".into_string()"), + "std::io::Error" if !is_ref => Some(".to_rust()"), "std::time::Duration"|"core::time::Duration" => Some(")"), "std::time::SystemTime" => Some("))"), diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 6267b80..b6b1bbf 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -198,6 +198,28 @@ impl IOError { _ => IOError::Other, } } + pub(crate) fn to_rust(&self) -> std::io::Error { + std::io::Error::new(match self { + IOError::NotFound => std::io::ErrorKind::NotFound, + IOError::PermissionDenied => std::io::ErrorKind::PermissionDenied, + IOError::ConnectionRefused => std::io::ErrorKind::ConnectionRefused, + IOError::ConnectionReset => std::io::ErrorKind::ConnectionReset, + IOError::ConnectionAborted => std::io::ErrorKind::ConnectionAborted, + IOError::NotConnected => std::io::ErrorKind::NotConnected, + IOError::AddrInUse => std::io::ErrorKind::AddrInUse, + IOError::AddrNotAvailable => std::io::ErrorKind::AddrNotAvailable, + IOError::BrokenPipe => std::io::ErrorKind::BrokenPipe, + IOError::AlreadyExists => std::io::ErrorKind::AlreadyExists, + IOError::WouldBlock => std::io::ErrorKind::WouldBlock, + IOError::InvalidInput => std::io::ErrorKind::InvalidInput, + IOError::InvalidData => std::io::ErrorKind::InvalidData, + IOError::TimedOut => std::io::ErrorKind::TimedOut, + IOError::WriteZero => std::io::ErrorKind::WriteZero, + IOError::Interrupted => std::io::ErrorKind::Interrupted, + IOError::Other => std::io::ErrorKind::Other, + IOError::UnexpectedEof => std::io::ErrorKind::UnexpectedEof, + }, "") + } } #[repr(C)]