fire-stream-api 0.3.4

A more or less simple communication protocol library.
Documentation
use std::fmt;
use std::error::Error as StdError;
use std::borrow::Cow;

pub use stream::error::RequestError;


/// The error that is sent if something goes wrong while responding
/// to a request.
pub trait ApiError: StdError {
	fn from_request_error(e: RequestError) -> Self;

	fn from_message_error(e: MessageError) -> Self;
}


#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
	MessageError(MessageError)
}

impl From<MessageError> for Error {
	fn from(e: MessageError) -> Self {
		Self::MessageError(e)
	}
}

impl fmt::Display for Error {
	fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
		fmt::Debug::fmt(self, fmt)
	}
}

impl StdError for Error {}

#[derive(Debug)]
#[non_exhaustive]
pub enum MessageError {
	#[cfg(feature = "json")]
	Json(serde_json::Error),
	// Protobuf
	#[cfg(feature = "protobuf")]
	EncodeError(fire_protobuf::encode::EncodeError),
	#[cfg(feature = "protobuf")]
	DecodeError(fire_protobuf::decode::DecodeError),
	Other(Cow<'static, str>)
}

impl fmt::Display for MessageError {
	fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
		fmt::Debug::fmt(self, fmt)
	}
}

impl StdError for MessageError {}