X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Fc_types%2Fmod.rs;h=14e37229cf497a44140eee30731b2e6a95d52390;hb=07fe5cf2e1b469125e8fdb97175593399888485b;hp=2748734cf6b7cfd25b0d8ddeb8e515bdd4e63a31;hpb=6c95131720d1d390bf006f5160dcf4aa878fa4f0;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 2748734..14e3722 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -110,6 +110,55 @@ impl Secp256k1Error { } } +#[repr(C)] +#[allow(missing_docs)] // If there's no docs upstream, that's good enough for us +/// Represents an IO Error. Note that some information is lost in the conversion from Rust. +pub enum IOError { + NotFound, + PermissionDenied, + ConnectionRefused, + ConnectionReset, + ConnectionAborted, + NotConnected, + AddrInUse, + AddrNotAvailable, + BrokenPipe, + AlreadyExists, + WouldBlock, + InvalidInput, + InvalidData, + TimedOut, + WriteZero, + Interrupted, + Other, + UnexpectedEof, +} +impl IOError { + pub(crate) fn from_rust(err: std::io::Error) -> Self { + match err.kind() { + std::io::ErrorKind::NotFound => IOError::NotFound, + std::io::ErrorKind::PermissionDenied => IOError::PermissionDenied, + std::io::ErrorKind::ConnectionRefused => IOError::ConnectionRefused, + std::io::ErrorKind::ConnectionReset => IOError::ConnectionReset, + std::io::ErrorKind::ConnectionAborted => IOError::ConnectionAborted, + std::io::ErrorKind::NotConnected => IOError::NotConnected, + std::io::ErrorKind::AddrInUse => IOError::AddrInUse, + std::io::ErrorKind::AddrNotAvailable => IOError::AddrNotAvailable, + std::io::ErrorKind::BrokenPipe => IOError::BrokenPipe, + std::io::ErrorKind::AlreadyExists => IOError::AlreadyExists, + std::io::ErrorKind::WouldBlock => IOError::WouldBlock, + std::io::ErrorKind::InvalidInput => IOError::InvalidInput, + std::io::ErrorKind::InvalidData => IOError::InvalidData, + std::io::ErrorKind::TimedOut => IOError::TimedOut, + std::io::ErrorKind::WriteZero => IOError::WriteZero, + std::io::ErrorKind::Interrupted => IOError::Interrupted, + std::io::ErrorKind::Other => IOError::Other, + std::io::ErrorKind::UnexpectedEof => IOError::UnexpectedEof, + _ => IOError::Other, + } + } +} + #[repr(C)] /// A serialized transaction, in (pointer, length) form. ///