#[repr(u8)]pub enum FtuiError {
Show 17 variants
TextFlagNoneWithOther,
TextFlagMultipleColor,
TextFlagAlignBottomWithListElement,
HeaderLabelEmpty,
OptionLabelEmpty,
ContainerLooperNoSelector,
ContainerNoSelector,
ContainerNoComponentById,
ListIndexOutOfBound,
ListNoElementById,
SelectorNoTriggers,
RendererContainerTooBig,
StdInputOutputError(Error),
TriggerCastArgNoArgument,
TriggerCastArgWrongType,
CallbackCastArgNoArgument,
CallbackCastArgWrongType,
}Expand description
An enum representing all possible errors that can occur in Feather-TUI.
§Derives
thiserror::Error, Debug
§PartialEq Implementation
This is necessary because the StdInputOutputError variant wraps a value of
type std::io::Error, which does not implement PartialEq. As a result, we
implement PartialEq manually, comparing all variants normally while treating
any two StdInputOutputError values as equal regardless of their internal
io::Error.
Variants§
TextFlagNoneWithOther
Occurs when TextFlags::NONE is used together with other flags.
§Example
fn main() -> FtuiResult<()> {
// Using `TextFlags::NONE` with TextFlags::COLOR_RED results in an error.
Text::new("Label", TextFlags::NONE | TextFlags::COLOR_RED)?;
Ok(())
}TextFlagMultipleColor
Occurs when multiple color flags are set for a Text component.
§Example
fn main() -> FtuiResult<()> {
// Setting both `COLOR_BLUE` and `COLOR_RED` results in an error.
Text::new("Label", TextFlags::COLOR_BLUE | TextFlags::COLOR_RED)?;
Ok(())
}TextFlagAlignBottomWithListElement
Occurs when attempting to use the TextFlags::ALIGN_BOTTOM flag with
a List element, which does not support bottom alignment.
§Example
fn main() -> FtuiResult<()> {
let mut list = List::new(...)?;
// Using `TextFlags::ALIGN_BOTTOM` will result in an error.
list.add(..., TextFlags::ALIGN_BOTTOM)?;
Ok(())
}HeaderLabelEmpty
Occurs when attempting to create a Header component with an empty label.
§Example
fn main() -> FtuiResult<()> {
// Creating a header with an empty label results in an error.
Header::new("")?;
Ok(())
}OptionLabelEmpty
Occurs when attempting to create an Option component with an empty label.
§Example
fn main() -> FtuiResult<()> {
// Creating an option with an empty label results in an error.
// Assuming the callback is created elsewhere.
Option::new("", ...)?;
Ok(())
}ContainerLooperNoSelector
Occurs when calling Container::loop on a container that has Option
components but does not have a Selector.
§Example
fn main() -> FtuiResult<()> {
// Create a container with an option component.
let mut container = ContainerBuilder::new()
.option(...)?;
// Attempting to call the loop method without a selector
container.looper()?;
Ok(())
}ContainerNoSelector
Occurs when attempting to use Container functionality that
requires a Selector, but the Container does not have one.
§Example
fn main() -> FtuiResult<()> {
// Create a container without a selector.
let mut container = ContainerBuilder::new().build();
// Attempting to call `selector_mut` on a container without a selector
// results in the error.
container.selector_mut()?;
Ok(())
}ContainerNoComponentById
Occurs when attempting to query a component by its ID, but no such component exists in the container.
§Example
fn main() -> FtuiResult<()> {
// Create an empty container.
let mut container = ContainerBuilder::new().build();
// Attempt to query using a non-existent ID.
// This results in the error.
container.option(172)?;
Ok(())
}ListIndexOutOfBound
Cccurs when performing an operation on a List container using an element
index that does not exist.
§Example
// Create a simple `List` container.
let mut list = ListBuilder::new().build();
// Add elements to the list.
list.add(...)?;
list.add(...)?;
// Attempt to access an out-of-bounds index, which will trigger this error.
list.at(100)?; ListNoElementById
Occurs when attempting to find the index of an element in a List
by its ID, but no element with the specified ID exists.
§Example
// Create a simple `List` container.
let mut list = ListBuilder::new().build();
// Add an element to the list and store its ID.
let id = list.add(...)?;
// Attempt to find an element by a non-existent ID.
list.find(id + 1)?; SelectorNoTriggers
Occurs when attempting to use Selector functionality that
requires triggers, but the Selector does not have one.
§Example
fn main() -> FtuiResult<()> {
// Create a `Selector` component with no triggers.
let mut selector = Selector::no_triggers();
// Attempting to use functionality that requires triggers.
// This results in the error.
selector.up_trig_mut()?;
Ok(())
}RendererContainerTooBig
Occurs when attempting to call the Renderer::render method with a container
that exceeds the dimensions of the renderer. There are two cases where a
container is considered “too big”:
- A component’s label is longer than the renderer’s width.
- The total number of components exceeds the renderer’s height.
§Example
fn main() -> FtuiResult<()> {
let mut container = ContainerBuilder::new()
.header("Header!")?
.text("Label", None)?;
// This will cause an error because the label "Header!" is 7 characters
// long, which is wider than the renderer width of 5.
let mut renderer = Renderer::new(5, 10);
renderer.render(&mut container)?;
// This will cause an error because the container has 2 components,
// but the renderer can only display 1 line (height = 1).
let mut renderer = Renderer::new(10, 1);
renderer.render(&mut container)?;
Ok(())
}StdInputOutputError(Error)
Occurs when functions in the input module fail. Affected functions
include line, key, and key_char. This enum wraps an error
from std::io::Error.
§Example
fn main() -> tui::err::FtuiResult<()> {
// This function may return an error if an I/O operation fails.
line("Prompt")?;
// This function may return an error if an I/O operation fails.
key()?;
// This function may return an error if an I/O operation fails.
key_char()?;
Ok(())
}TriggerCastArgNoArgument
Occurs when calling the trigger::cast_arg function with an argument
that is a None.
§Notes
- The trigger function argument has the type
&Option<Box<dyn Any>>.
§Example
// When creating a trigger using the no_arg constructor, the argument
// will be set to None.
Trigger::no_arg(trigger_func);
trg_new_trigger_func!(trigger_func, arg, {
// An error occurs because arg is None.
trg::cast_arg::<T>(arg)?;
});
TriggerCastArgWrongType
Occurs when calling the trigger::cast_arg function with an argument of
the wrong type.
§Notes
- The trigger function argument has the type
&Option<Box<dyn Any>>.
§Example
// Creating a trigger with an argument of 5, which is a u32.
Trigger::new(trigger_func, 5u32);
trg_new_trigger_func!(trigger_func, arg, {
// An error occurs because arg is a u32, but we're attempting to cast
// it to a char.
trg::cast_arg::<char>(arg)?;
});CallbackCastArgNoArgument
Occurs when calling the callback::cast_arg function with an argument
that is a None.
§Notes
- The callback function argument has the type
&Option<Box<dyn Any>>.
§Example
// When creating a callback using the no_arg constructor, the argument
// will be set to None.
cbk::Callback::no_arg(callback_func);
cbk_new_callback_func!(callback_func, arg, {
// An error occurs because arg is None.
cbk::cast_arg::<T>(arg)?;
});
CallbackCastArgWrongType
Occurs when calling the callback::cast_arg function with an argument of
the wrong type.
§Notes
- The callback function argument has the type
&Option<Box<dyn Any>>.
§Example
// Creating a callback with an argument of 5, which is a u32.
Callback::new(callback_func, 5u32);
callback_new_callback_func!(callback_func, arg, {
// An error occurs because arg is a u32, but we're attempting to cast
// it to a char.
cbk::cast_arg::<char>(arg)?;
});Trait Implementations§
Source§impl Error for FtuiError
impl Error for FtuiError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl PartialEq for FtuiError
Implementation of the PartialEq trait for the FtuiError enum. This is necessary
because the StdInputOutputError variant wraps a value of type std::io::Error,
which does not implement PartialEq. As a result, we implement PartialEq
manually, comparing all variants normally while treating any two StdInputOutputError
values as equal regardless of their internal io::Error.
impl PartialEq for FtuiError
Implementation of the PartialEq trait for the FtuiError enum. This is necessary
because the StdInputOutputError variant wraps a value of type std::io::Error,
which does not implement PartialEq. As a result, we implement PartialEq
manually, comparing all variants normally while treating any two StdInputOutputError
values as equal regardless of their internal io::Error.
§Examples
// Variants of the same type are considered equal.
assert_eq!(
FtuiError::TextFlagNoneWithOther, FtuiError::TextFlagNoneWithOther);
// Variants of different types are not equal.
assert_ne!(
FtuiError::TextFlagNoneWithOther, FtuiError::TextFlagMultipleColor);
// StdInputOutputError variants are treated as equal even if their inner errors differ.
use std::io::{Error, ErrorKind};
assert_eq!(
FtuiError::StdInputOutputError(Error::from(ErrorKind::NotFound)),
FtuiError::StdInputOutputError(Error::from(ErrorKind::PermissionDenied)));