lnsocket 0.1.1

An async lightning network socket with with core-lightning rpc support
Documentation
use crate::ln::msgs::{DecodeError, LightningError};
use std::fmt;
use std::io;
use std::net::AddrParseError;

#[derive(Debug)]
pub enum Error {
    NotConnected,
    FirstMessageNotInit,
    DnsError,
    Io(io::ErrorKind),
    Json(serde_json::Error),
    Lightning(LightningError),
    Decode(DecodeError),
    AddrParse(std::net::AddrParseError),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::NotConnected => write!(f, "Not connected to server"),
            Error::FirstMessageNotInit => write!(f, "First message was not init"),
            Error::DnsError => write!(f, "Failed to resolve hostname"),
            Error::Io(kind) => write!(f, "I/O error: {}", kind),
            Error::Lightning(err) => write!(f, "Lightning error: {:?}", err),
            Error::Decode(err) => write!(f, "decoding error: {:?}", err),
            Error::Json(err) => write!(f, "json error: {:?}", err),
            Error::AddrParse(err) => write!(f, "Address parse error: {}", err),
        }
    }
}

impl From<io::Error> for Error {
    fn from(err: io::Error) -> Self {
        Self::Io(err.kind())
    }
}

impl From<serde_json::Error> for Error {
    fn from(err: serde_json::Error) -> Self {
        Self::Json(err)
    }
}

impl From<DecodeError> for Error {
    fn from(decode: DecodeError) -> Self {
        Self::Decode(decode)
    }
}

impl From<LightningError> for Error {
    fn from(lnerr: LightningError) -> Self {
        Self::Lightning(lnerr)
    }
}

impl From<AddrParseError> for Error {
    fn from(err: AddrParseError) -> Self {
        Self::AddrParse(err)
    }
}