use thiserror::Error;
use std::io;
#[repr(u8)]
#[derive(Error, Debug)]
pub enum FtuiError {
#[error("TextFlags::NONE cannot be combined with other TextFlags.")]
TextFlagNoneWithOther,
#[error("TextFlags cannot contain multiple color.")]
TextFlagMultipleColor,
#[error("TextFlags::ALIGN_BOTTOM is not supported for list elements.")]
TextFlagAlignBottomWithListElement,
#[error("A Header label cannot be empty.")]
HeaderLabelEmpty,
#[error("An Option label cannot be empty.")]
OptionLabelEmpty,
#[error("The container's looper method requires a Selector.")]
ContainerLooperNoSelector,
#[error("Container doesnot have a Selector.")]
ContainerNoSelector,
#[error("Failed to query for component by its ID")]
ContainerNoComponentById,
#[error("List index is out of bound.")]
ListIndexOutOfBound,
#[error("No element found with the specified ID.")]
ListNoElementById,
#[error("Selector does not have triggers.")]
SelectorNoTriggers,
#[error("Container is bigger than what the renderer can accommodate.")]
RendererContainerTooBig,
#[error("Std Input Output Error: {0}")]
StdInputOutputError(#[from] io::Error),
#[error("Trigger function does not have an argument available for casting.")]
TriggerCastArgNoArgument,
#[error("Trigger function argument type mismatch unable to cast to the expected type.")]
TriggerCastArgWrongType,
#[error("Callback function does not have an argument available for casting.")]
CallbackCastArgNoArgument,
#[error("Callback function argument type mismatch unable to cast to the expected type.")]
CallbackCastArgWrongType,
}
impl PartialEq for FtuiError {
fn eq(&self, other: &Self) -> bool {
use FtuiError::*;
match (self, other) {
(TextFlagNoneWithOther, TextFlagNoneWithOther) => true,
(TextFlagMultipleColor, TextFlagMultipleColor) => true,
(HeaderLabelEmpty, HeaderLabelEmpty) => true,
(OptionLabelEmpty, OptionLabelEmpty) => true,
(ContainerLooperNoSelector, ContainerLooperNoSelector) => true,
(ContainerNoSelector, ContainerNoSelector) => true,
(ContainerNoComponentById, ContainerNoComponentById) => true,
(ListIndexOutOfBound, ListIndexOutOfBound) => true,
(ListNoElementById, ListNoElementById) => true,
(SelectorNoTriggers, SelectorNoTriggers) => true,
(RendererContainerTooBig, RendererContainerTooBig) => true,
(StdInputOutputError(_), StdInputOutputError(_)) => true,
(TriggerCastArgNoArgument, TriggerCastArgNoArgument) => true,
(TriggerCastArgWrongType, TriggerCastArgWrongType) => true,
(CallbackCastArgNoArgument, CallbackCastArgNoArgument) => true,
(CallbackCastArgWrongType, CallbackCastArgWrongType) => true,
_ => false,
}
}
}
pub type FtuiResult<T> = Result<T, FtuiError>;