tatami 0.1.1

A library for creating satellites and interacting with Tatami protocols.
Documentation
use thiserror::Error;

#[derive(Error, Debug)]
pub enum TatamiError {
	#[error("a generic error occured")]
	Generic,
	#[error("the satellite broke down")]
	Breakdown,
	#[error("there was an error with Shoji: {0}")]
	Shoji(ShojiError),
}

#[derive(Error, Debug)]
pub enum ShojiError {
	#[error("a generic error occured")]
	Generic,
	#[error("the paper-wall tore, messages were lost")]
	Tear,
}

// Error Conversions!

#[cfg(feature = "tokio")]
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for ShojiError {
	fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self {
		Self::Tear
	}
}

#[cfg(feature = "tokio")]
impl From<tokio::sync::oneshot::error::RecvError> for ShojiError {
	fn from(_: tokio::sync::oneshot::error::RecvError) -> Self {
		Self::Tear
	}
}

#[cfg(feature = "tokio")]
impl From<tokio::sync::oneshot::error::RecvError> for TatamiError {
	fn from(_: tokio::sync::oneshot::error::RecvError) -> Self {
		Self::Shoji(ShojiError::Tear)
	}
}

#[cfg(feature = "tokio")]
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for TatamiError {
	fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self {
		Self::Shoji(ShojiError::Tear)
	}
}

impl From<ShojiError> for TatamiError {
	fn from(e: ShojiError) -> Self {
		Self::Shoji(e)
	}
}

cfg_if::cfg_if! {
	if #[cfg(feature = "satellite")] {
		use libp2p::{swarm::DialError, TransportError};
		use tracing::warn;
		use std::io;

		impl From<DialError> for ShojiError {
			fn from(_: DialError) -> Self {
				warn!("This error needs to be better");
				Self::Generic
			}
		}

		impl From<DialError> for TatamiError {
			fn from(_: DialError) -> Self {
				warn!("This error needs to be better");
				Self::Generic
			}
		}

		impl From<TransportError<io::Error>> for ShojiError {
			fn from(_: TransportError<io::Error>) -> Self {
				warn!("This error needs to be better");
				Self::Generic
			}
		}
	} else {}
}