pub trait Item: Display + Clone {
// Required method
fn filter_value(&self) -> String;
}Expand description
Core traits and types for list functionality.
These are the fundamental building blocks for creating custom list items and delegates:
Item: Trait for displayable and filterable list itemsItemDelegate: Trait for customizing item rendering and behaviorFilterState: Enum representing the current filtering stateFilterStateInfo: Detailed information about filter status
§Examples
use bubbletea_widgets::list::{Item, ItemDelegate, FilterState, Model};
use std::fmt::Display;
#[derive(Clone)]
struct MyItem {
name: String,
value: i32,
}
impl Display for MyItem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}: {}", self.name, self.value)
}
}
impl Item for MyItem {
fn filter_value(&self) -> String {
format!("{} {}", self.name, self.value)
}
}Trait for items that can be displayed and filtered in a list.
Items must be displayable and cloneable to work with the list component.
The filter_value() method determines what text is used when searching
through items with the fuzzy filter.
§Examples
use bubbletea_widgets::list::Item;
use std::fmt::Display;
#[derive(Clone)]
struct Task {
name: String,
description: String,
}
impl Display for Task {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name)
}
}
impl Item for Task {
fn filter_value(&self) -> String {
// Filter searches both name and description
format!("{} {}", self.name, self.description)
}
}Required Methods§
Sourcefn filter_value(&self) -> String
fn filter_value(&self) -> String
Returns the text used for fuzzy filtering this item.
This method should return a string that represents all searchable content for the item. The fuzzy matcher will search within this text when the user types a filter query.
§Returns
A string containing all text that should be searchable for this item. Common patterns include returning just the display name, or combining multiple fields like “name description tags”.
§Examples
use bubbletea_widgets::list::Item;
#[derive(Clone)]
struct MyItem(String);
impl std::fmt::Display for MyItem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl Item for MyItem {
fn filter_value(&self) -> String {
self.0.clone()
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.