fix: must_use the structs

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