FtuiError

Enum FtuiError 

Source
#[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”:

  1. A component’s label is longer than the renderer’s width.
  2. 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 Debug for FtuiError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for FtuiError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for FtuiError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for FtuiError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
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.

§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)));
Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.