Skip to content

Commit 7ca42fa

Browse files
committed
Map io::ErrorKind the same as io::Error, we only use the kind
1 parent 1830b38 commit 7ca42fa

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

c-bindings-gen/src/types.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
932932

933933
"std::time::Duration"|"core::time::Duration" => Some("u64"),
934934
"std::time::SystemTime" => Some("u64"),
935-
"std::io::Error"|"lightning::io::Error" => Some("crate::c_types::IOError"),
935+
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some("crate::c_types::IOError"),
936936
"core::fmt::Arguments" if is_ref => Some("crate::c_types::Str"),
937937

938938
"core::convert::Infallible" => Some("crate::c_types::NotConstructable"),
@@ -1017,7 +1017,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10171017

10181018
"str" if is_ref => Some(""),
10191019
"alloc::string::String"|"String" => Some(""),
1020-
"std::io::Error"|"lightning::io::Error" => Some(""),
1020+
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some(""),
10211021
// Note that we'll panic for String if is_ref, as we only have non-owned memory, we
10221022
// cannot create a &String.
10231023

@@ -1108,6 +1108,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11081108
"str" if is_ref => Some(".into_str()"),
11091109
"alloc::string::String"|"String" => Some(".into_string()"),
11101110
"std::io::Error"|"lightning::io::Error" => Some(".to_rust()"),
1111+
"lightning::io::ErrorKind" => Some(".to_rust_kind()"),
11111112

11121113
"core::convert::Infallible" => Some("\")"),
11131114

@@ -1204,6 +1205,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12041205
"std::time::Duration"|"core::time::Duration" => Some(""),
12051206
"std::time::SystemTime" => Some(""),
12061207
"std::io::Error"|"lightning::io::Error" => Some("crate::c_types::IOError::from_rust("),
1208+
"lightning::io::ErrorKind" => Some("crate::c_types::IOError::from_rust_kind("),
12071209
"core::fmt::Arguments" => Some("alloc::format!(\"{}\", "),
12081210

12091211
"core::convert::Infallible" => Some("panic!(\"Cannot construct an Infallible: "),
@@ -1283,7 +1285,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12831285

12841286
"std::time::Duration"|"core::time::Duration" => Some(".as_secs()"),
12851287
"std::time::SystemTime" => Some(".duration_since(::std::time::SystemTime::UNIX_EPOCH).expect(\"Times must be post-1970\").as_secs()"),
1286-
"std::io::Error"|"lightning::io::Error" => Some(")"),
1288+
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some(")"),
12871289
"core::fmt::Arguments" => Some(").into()"),
12881290

12891291
"core::convert::Infallible" => Some("\")"),

lightning-c-bindings/src/c_types/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ pub enum IOError {
316316
UnexpectedEof,
317317
}
318318
impl IOError {
319-
pub(crate) fn from_rust(err: io::Error) -> Self {
320-
match err.kind() {
319+
pub(crate) fn from_rust_kind(err: io::ErrorKind) -> Self {
320+
match err {
321321
io::ErrorKind::NotFound => IOError::NotFound,
322322
io::ErrorKind::PermissionDenied => IOError::PermissionDenied,
323323
io::ErrorKind::ConnectionRefused => IOError::ConnectionRefused,
@@ -339,8 +339,11 @@ impl IOError {
339339
_ => IOError::Other,
340340
}
341341
}
342-
pub(crate) fn to_rust(&self) -> io::Error {
343-
io::Error::new(match self {
342+
pub(crate) fn from_rust(err: io::Error) -> Self {
343+
Self::from_rust_kind(err.kind())
344+
}
345+
pub(crate) fn to_rust_kind(&self) -> io::ErrorKind {
346+
match self {
344347
IOError::NotFound => io::ErrorKind::NotFound,
345348
IOError::PermissionDenied => io::ErrorKind::PermissionDenied,
346349
IOError::ConnectionRefused => io::ErrorKind::ConnectionRefused,
@@ -359,7 +362,10 @@ impl IOError {
359362
IOError::Interrupted => io::ErrorKind::Interrupted,
360363
IOError::Other => io::ErrorKind::Other,
361364
IOError::UnexpectedEof => io::ErrorKind::UnexpectedEof,
362-
}, "")
365+
}
366+
}
367+
pub(crate) fn to_rust(&self) -> io::Error {
368+
io::Error::new(self.to_rust_kind(), "")
363369
}
364370
}
365371

0 commit comments

Comments
 (0)