fix: must_use the structs
This commit is contained in:
+4
-3
@@ -6,6 +6,7 @@ use ratatui::layout::Rect;
|
|||||||
use ratatui::widgets::StatefulWidget;
|
use ratatui::widgets::StatefulWidget;
|
||||||
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
fn example_items() -> Vec<TreeItem<'static, &'static str>> {
|
fn example_items() -> Vec<TreeItem<'static, &'static str>> {
|
||||||
vec![
|
vec![
|
||||||
TreeItem::new_leaf("a", "Alfa"),
|
TreeItem::new_leaf("a", "Alfa"),
|
||||||
@@ -73,15 +74,15 @@ fn init(criterion: &mut Criterion) {
|
|||||||
|
|
||||||
group.bench_function("empty", |bencher| {
|
group.bench_function("empty", |bencher| {
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
let items: Vec<TreeItem<usize>> = vec![];
|
let items = vec![];
|
||||||
black_box(Tree::new(black_box(&items))).unwrap();
|
let _: Tree<usize> = black_box(Tree::new(black_box(&items))).unwrap();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group.bench_function("example-items", |bencher| {
|
group.bench_function("example-items", |bencher| {
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
let items = example_items();
|
let items = example_items();
|
||||||
black_box(Tree::new(black_box(&items))).unwrap();
|
let _: Tree<_> = black_box(Tree::new(black_box(&items))).unwrap();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use ratatui::widgets::{Block, Scrollbar, ScrollbarOrientation};
|
|||||||
use ratatui::{Frame, Terminal};
|
use ratatui::{Frame, Terminal};
|
||||||
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
struct App {
|
struct App {
|
||||||
state: TreeState<&'static str>,
|
state: TreeState<&'static str>,
|
||||||
items: Vec<TreeItem<'static, &'static str>>,
|
items: Vec<TreeItem<'static, &'static str>>,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::tree_item::TreeItem;
|
|||||||
/// A flattened item of all visible [`TreeItem`]s.
|
/// A flattened item of all visible [`TreeItem`]s.
|
||||||
///
|
///
|
||||||
/// Generated via [`TreeState::flatten`](crate::TreeState::flatten).
|
/// Generated via [`TreeState::flatten`](crate::TreeState::flatten).
|
||||||
|
#[must_use]
|
||||||
pub struct Flattened<'text, Identifier> {
|
pub struct Flattened<'text, Identifier> {
|
||||||
pub identifier: Vec<Identifier>,
|
pub identifier: Vec<Identifier>,
|
||||||
pub item: &'text TreeItem<'text, Identifier>,
|
pub item: &'text TreeItem<'text, Identifier>,
|
||||||
|
|||||||
+3
-9
@@ -50,6 +50,7 @@ mod tree_state;
|
|||||||
/// })?;
|
/// })?;
|
||||||
/// # Ok::<(), std::io::Error>(())
|
/// # Ok::<(), std::io::Error>(())
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Tree<'a, Identifier> {
|
pub struct Tree<'a, Identifier> {
|
||||||
items: &'a [TreeItem<'a, Identifier>],
|
items: &'a [TreeItem<'a, Identifier>],
|
||||||
@@ -107,7 +108,6 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::missing_const_for_fn)]
|
#[allow(clippy::missing_const_for_fn)]
|
||||||
#[must_use]
|
|
||||||
pub fn block(mut self, block: Block<'a>) -> Self {
|
pub fn block(mut self, block: Block<'a>) -> Self {
|
||||||
self.block = Some(block);
|
self.block = Some(block);
|
||||||
self
|
self
|
||||||
@@ -118,43 +118,36 @@ where
|
|||||||
/// Experimental: Can change on any release without any additional notice.
|
/// Experimental: Can change on any release without any additional notice.
|
||||||
/// Its there to test and experiment with whats possible with scrolling widgets.
|
/// Its there to test and experiment with whats possible with scrolling widgets.
|
||||||
/// Also see <https://github.com/ratatui-org/ratatui/issues/174>
|
/// Also see <https://github.com/ratatui-org/ratatui/issues/174>
|
||||||
#[must_use]
|
|
||||||
pub const fn experimental_scrollbar(mut self, scrollbar: Option<Scrollbar<'a>>) -> Self {
|
pub const fn experimental_scrollbar(mut self, scrollbar: Option<Scrollbar<'a>>) -> Self {
|
||||||
self.scrollbar = scrollbar;
|
self.scrollbar = scrollbar;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn style(mut self, style: Style) -> Self {
|
pub const fn style(mut self, style: Style) -> Self {
|
||||||
self.style = style;
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn highlight_style(mut self, style: Style) -> Self {
|
pub const fn highlight_style(mut self, style: Style) -> Self {
|
||||||
self.highlight_style = style;
|
self.highlight_style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn highlight_symbol(mut self, highlight_symbol: &'a str) -> Self {
|
pub const fn highlight_symbol(mut self, highlight_symbol: &'a str) -> Self {
|
||||||
self.highlight_symbol = highlight_symbol;
|
self.highlight_symbol = highlight_symbol;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn node_closed_symbol(mut self, symbol: &'a str) -> Self {
|
pub const fn node_closed_symbol(mut self, symbol: &'a str) -> Self {
|
||||||
self.node_closed_symbol = symbol;
|
self.node_closed_symbol = symbol;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn node_open_symbol(mut self, symbol: &'a str) -> Self {
|
pub const fn node_open_symbol(mut self, symbol: &'a str) -> Self {
|
||||||
self.node_open_symbol = symbol;
|
self.node_open_symbol = symbol;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub const fn node_no_children_symbol(mut self, symbol: &'a str) -> Self {
|
pub const fn node_no_children_symbol(mut self, symbol: &'a str) -> Self {
|
||||||
self.node_no_children_symbol = symbol;
|
self.node_no_children_symbol = symbol;
|
||||||
self
|
self
|
||||||
@@ -166,7 +159,8 @@ where
|
|||||||
fn tree_new_errors_with_duplicate_identifiers() {
|
fn tree_new_errors_with_duplicate_identifiers() {
|
||||||
let item = TreeItem::new_leaf("same", "text");
|
let item = TreeItem::new_leaf("same", "text");
|
||||||
let another = item.clone();
|
let another = item.clone();
|
||||||
Tree::new(&[item, another]).unwrap();
|
let items = [item, another];
|
||||||
|
let _: Tree<_> = Tree::new(&items).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Identifier> StatefulWidget for Tree<'_, Identifier>
|
impl<Identifier> StatefulWidget for Tree<'_, Identifier>
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ where
|
|||||||
|
|
||||||
impl TreeItem<'static, &'static str> {
|
impl TreeItem<'static, &'static str> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[must_use]
|
||||||
pub(crate) fn example() -> Vec<Self> {
|
pub(crate) fn example() -> Vec<Self> {
|
||||||
vec![
|
vec![
|
||||||
Self::new_leaf("a", "Alfa"),
|
Self::new_leaf("a", "Alfa"),
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use crate::tree_item::TreeItem;
|
|||||||
///
|
///
|
||||||
/// let mut state = TreeState::<Identifier>::default();
|
/// let mut state = TreeState::<Identifier>::default();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use]
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct TreeState<Identifier> {
|
pub struct TreeState<Identifier> {
|
||||||
pub(super) offset: usize,
|
pub(super) offset: usize,
|
||||||
|
|||||||
Reference in New Issue
Block a user