Skip to content

Commit

Permalink
fix: must_use the structs
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed May 23, 2024
1 parent 1365992 commit d676f66
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
7 changes: 4 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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();
});
});

Expand Down
1 change: 1 addition & 0 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down
1 change: 1 addition & 0 deletions src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
12 changes: 3 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>],
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/tree_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions src/tree_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d676f66

Please sign in to comment.