diff --git a/Cargo.toml b/Cargo.toml index f40bf22d..18e1e3f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ serde_json = "1.0.109" unsafe_code = "forbid" [lints.clippy] explicit_iter_loop = "warn" +missing_const_for_fn = "warn" needless_for_each = "warn" semicolon_if_nothing_returned = "warn" diff --git a/src/backend/crossterm.rs b/src/backend/crossterm.rs index afbeb4f7..55d5c5f6 100644 --- a/src/backend/crossterm.rs +++ b/src/backend/crossterm.rs @@ -97,7 +97,7 @@ where /// # use ratatui::prelude::*; /// let backend = CrosstermBackend::new(stdout()); /// ``` - pub fn new(writer: W) -> CrosstermBackend { + pub const fn new(writer: W) -> CrosstermBackend { CrosstermBackend { writer } } } diff --git a/src/backend/termion.rs b/src/backend/termion.rs index f1b9d766..2bb16133 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -82,7 +82,7 @@ where /// # use ratatui::prelude::*; /// let backend = TermionBackend::new(stdout()); /// ``` - pub fn new(writer: W) -> TermionBackend { + pub const fn new(writer: W) -> TermionBackend { TermionBackend { writer } } } diff --git a/src/backend/termwiz.rs b/src/backend/termwiz.rs index e526343c..87463d80 100644 --- a/src/backend/termwiz.rs +++ b/src/backend/termwiz.rs @@ -93,14 +93,16 @@ impl TermwizBackend { } /// Creates a new Termwiz backend instance with the given buffered terminal. - pub fn with_buffered_terminal(instance: BufferedTerminal) -> TermwizBackend { + pub const fn with_buffered_terminal( + instance: BufferedTerminal, + ) -> TermwizBackend { TermwizBackend { buffered_terminal: instance, } } /// Returns a reference to the buffered terminal used by the backend. - pub fn buffered_terminal(&self) -> &BufferedTerminal { + pub const fn buffered_terminal(&self) -> &BufferedTerminal { &self.buffered_terminal } diff --git a/src/backend/test.rs b/src/backend/test.rs index 310978f5..af0d5581 100644 --- a/src/backend/test.rs +++ b/src/backend/test.rs @@ -84,7 +84,7 @@ impl TestBackend { } /// Returns a reference to the internal buffer of the TestBackend. - pub fn buffer(&self) -> &Buffer { + pub const fn buffer(&self) -> &Buffer { &self.buffer } diff --git a/src/buffer/buffer.rs b/src/buffer/buffer.rs index 880dcb64..cfdab2c8 100644 --- a/src/buffer/buffer.rs +++ b/src/buffer/buffer.rs @@ -92,7 +92,7 @@ impl Buffer { } /// Returns the area covered by this buffer - pub fn area(&self) -> &Rect { + pub const fn area(&self) -> &Rect { &self.area } diff --git a/src/terminal/frame.rs b/src/terminal/frame.rs index f0885c9e..e6547804 100644 --- a/src/terminal/frame.rs +++ b/src/terminal/frame.rs @@ -49,7 +49,7 @@ impl Frame<'_> { /// If your app listens for a resize event from the backend, it should ignore the values from /// the event for any calculations that are used to render the current frame and use this value /// instead as this is the size of the buffer that is used to render the current frame. - pub fn size(&self) -> Rect { + pub const fn size(&self) -> Rect { self.viewport_area } @@ -193,7 +193,7 @@ impl Frame<'_> { /// let current_count = frame.count(); /// println!("Current frame count: {}", current_count); /// ``` - pub fn count(&self) -> usize { + pub const fn count(&self) -> usize { self.count } } diff --git a/src/terminal/terminal.rs b/src/terminal/terminal.rs index a501bcdf..f6befefd 100644 --- a/src/terminal/terminal.rs +++ b/src/terminal/terminal.rs @@ -172,7 +172,7 @@ where } /// Gets the backend - pub fn backend(&self) -> &B { + pub const fn backend(&self) -> &B { &self.backend } diff --git a/src/text/masked.rs b/src/text/masked.rs index b657e95a..f567ca1f 100644 --- a/src/text/masked.rs +++ b/src/text/masked.rs @@ -36,7 +36,7 @@ impl<'a> Masked<'a> { } /// The character to use for masking. - pub fn mask_char(&self) -> char { + pub const fn mask_char(&self) -> char { self.mask_char } diff --git a/src/widgets/barchart.rs b/src/widgets/barchart.rs index bfffd1a3..acdc5915 100644 --- a/src/widgets/barchart.rs +++ b/src/widgets/barchart.rs @@ -163,7 +163,7 @@ impl<'a> BarChart<'a> { /// // f b b /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn max(mut self, max: u64) -> BarChart<'a> { + pub const fn max(mut self, max: u64) -> BarChart<'a> { self.max = Some(max); self } @@ -213,7 +213,7 @@ impl<'a> BarChart<'a> { /// // f b /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn bar_gap(mut self, gap: u16) -> BarChart<'a> { + pub const fn bar_gap(mut self, gap: u16) -> BarChart<'a> { self.bar_gap = gap; self } @@ -222,7 +222,7 @@ impl<'a> BarChart<'a> { /// /// If not set, the default is [`bar::NINE_LEVELS`](crate::symbols::bar::NINE_LEVELS). #[must_use = "method moves the value of self and returns the modified value"] - pub fn bar_set(mut self, bar_set: symbols::bar::Set) -> BarChart<'a> { + pub const fn bar_set(mut self, bar_set: symbols::bar::Set) -> BarChart<'a> { self.bar_set = bar_set; self } @@ -263,7 +263,7 @@ impl<'a> BarChart<'a> { /// Set the gap between [`BarGroup`]. #[must_use = "method moves the value of self and returns the modified value"] - pub fn group_gap(mut self, gap: u16) -> BarChart<'a> { + pub const fn group_gap(mut self, gap: u16) -> BarChart<'a> { self.group_gap = gap; self } @@ -300,7 +300,7 @@ impl<'a> BarChart<'a> { /// █bar██ /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn direction(mut self, direction: Direction) -> BarChart<'a> { + pub const fn direction(mut self, direction: Direction) -> BarChart<'a> { self.direction = direction; self } diff --git a/src/widgets/barchart/bar.rs b/src/widgets/barchart/bar.rs index 02b11a82..d355d9a5 100644 --- a/src/widgets/barchart/bar.rs +++ b/src/widgets/barchart/bar.rs @@ -50,7 +50,7 @@ impl<'a> Bar<'a> { /// [`Bar::value_style`] to style the value. /// [`Bar::text_value`] to set the displayed value. #[must_use = "method moves the value of self and returns the modified value"] - pub fn value(mut self, value: u64) -> Bar<'a> { + pub const fn value(mut self, value: u64) -> Bar<'a> { self.value = value; self } diff --git a/src/widgets/block.rs b/src/widgets/block.rs index 04115b64..66d86ee6 100644 --- a/src/widgets/block.rs +++ b/src/widgets/block.rs @@ -1107,7 +1107,7 @@ mod tests { } #[test] - fn border_type_can_be_const() { + const fn border_type_can_be_const() { const _PLAIN: border::Set = BorderType::border_symbols(BorderType::Plain); } @@ -1130,7 +1130,7 @@ mod tests { } #[test] - fn block_can_be_const() { + const fn block_can_be_const() { const _DEFAULT_STYLE: Style = Style::new(); const _DEFAULT_PADDING: Padding = Padding::uniform(1); const _DEFAULT_BLOCK: Block = Block::new() diff --git a/src/widgets/block/padding.rs b/src/widgets/block/padding.rs index 2bf36fc1..d79248d3 100644 --- a/src/widgets/block/padding.rs +++ b/src/widgets/block/padding.rs @@ -186,7 +186,7 @@ mod tests { } #[test] - fn can_be_const() { + const fn can_be_const() { const _PADDING: Padding = Padding::new(1, 1, 1, 1); const _UNI_PADDING: Padding = Padding::uniform(1); const _NO_PADDING: Padding = Padding::zero(); diff --git a/src/widgets/block/title.rs b/src/widgets/block/title.rs index 22a072c8..a733d742 100644 --- a/src/widgets/block/title.rs +++ b/src/widgets/block/title.rs @@ -97,14 +97,14 @@ impl<'a> Title<'a> { /// Set the title alignment. #[must_use = "method moves the value of self and returns the modified value"] - pub fn alignment(mut self, alignment: Alignment) -> Title<'a> { + pub const fn alignment(mut self, alignment: Alignment) -> Title<'a> { self.alignment = Some(alignment); self } /// Set the title position. #[must_use = "method moves the value of self and returns the modified value"] - pub fn position(mut self, position: Position) -> Title<'a> { + pub const fn position(mut self, position: Position) -> Title<'a> { self.position = Some(position); self } diff --git a/src/widgets/canvas.rs b/src/widgets/canvas.rs index e1c68718..00b2a4c7 100644 --- a/src/widgets/canvas.rs +++ b/src/widgets/canvas.rs @@ -671,7 +671,7 @@ where /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn x_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> { + pub const fn x_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> { self.x_bounds = bounds; self } @@ -683,7 +683,7 @@ where /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn y_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> { + pub const fn y_bounds(mut self, bounds: [f64; 2]) -> Canvas<'a, F> { self.y_bounds = bounds; self } @@ -701,7 +701,7 @@ where /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn background_color(mut self, color: Color) -> Canvas<'a, F> { + pub const fn background_color(mut self, color: Color) -> Canvas<'a, F> { self.background_color = color; self } @@ -744,7 +744,7 @@ where /// .marker(symbols::Marker::Block) /// .paint(|ctx| {}); /// ``` - pub fn marker(mut self, marker: symbols::Marker) -> Canvas<'a, F> { + pub const fn marker(mut self, marker: symbols::Marker) -> Canvas<'a, F> { self.marker = marker; self } diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs index 182b1db8..6f5f563d 100644 --- a/src/widgets/chart.rs +++ b/src/widgets/chart.rs @@ -70,7 +70,7 @@ impl<'a> Axis<'a> { /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn bounds(mut self, bounds: [f64; 2]) -> Axis<'a> { + pub const fn bounds(mut self, bounds: [f64; 2]) -> Axis<'a> { self.bounds = bounds; self } @@ -133,7 +133,7 @@ impl<'a> Axis<'a> { /// /// On the X axis, this parameter only affects the first label. #[must_use = "method moves the value of self and returns the modified value"] - pub fn labels_alignment(mut self, alignment: Alignment) -> Axis<'a> { + pub const fn labels_alignment(mut self, alignment: Alignment) -> Axis<'a> { self.labels_alignment = alignment; self } @@ -341,7 +341,7 @@ impl<'a> Dataset<'a> { /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn data(mut self, data: &'a [(f64, f64)]) -> Dataset<'a> { + pub const fn data(mut self, data: &'a [(f64, f64)]) -> Dataset<'a> { self.data = data; self } @@ -356,7 +356,7 @@ impl<'a> Dataset<'a> { /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn marker(mut self, marker: symbols::Marker) -> Dataset<'a> { + pub const fn marker(mut self, marker: symbols::Marker) -> Dataset<'a> { self.marker = marker; self } @@ -369,7 +369,7 @@ impl<'a> Dataset<'a> { /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn graph_type(mut self, graph_type: GraphType) -> Dataset<'a> { + pub const fn graph_type(mut self, graph_type: GraphType) -> Dataset<'a> { self.graph_type = graph_type; self } @@ -648,7 +648,10 @@ impl<'a> Chart<'a> { /// let chart = Chart::new(vec![]).hidden_legend_constraints(constraints); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn hidden_legend_constraints(mut self, constraints: (Constraint, Constraint)) -> Chart<'a> { + pub const fn hidden_legend_constraints( + mut self, + constraints: (Constraint, Constraint), + ) -> Chart<'a> { self.hidden_legend_constraints = constraints; self } @@ -683,7 +686,7 @@ impl<'a> Chart<'a> { /// let chart = Chart::new(vec![]).legend_position(None); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn legend_position(mut self, position: Option) -> Chart<'a> { + pub const fn legend_position(mut self, position: Option) -> Chart<'a> { self.legend_position = position; self } diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index 489516d8..8f947ec9 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -147,7 +147,7 @@ impl<'a> Gauge<'a> { /// [unicode block characters](https://en.wikipedia.org/wiki/Block_Elements). /// This is useful to display a higher precision bar (8 extra fractional parts per cell). #[must_use = "method moves the value of self and returns the modified value"] - pub fn use_unicode(mut self, unicode: bool) -> Gauge<'a> { + pub const fn use_unicode(mut self, unicode: bool) -> Gauge<'a> { self.use_unicode = unicode; self } @@ -307,7 +307,7 @@ impl<'a> LineGauge<'a> { /// [`NORMAL`](symbols::line::NORMAL), [`DOUBLE`](symbols::line::DOUBLE) and /// [`THICK`](symbols::line::THICK). #[must_use = "method moves the value of self and returns the modified value"] - pub fn line_set(mut self, set: symbols::line::Set) -> Self { + pub const fn line_set(mut self, set: symbols::line::Set) -> Self { self.line_set = set; self } diff --git a/src/widgets/list.rs b/src/widgets/list.rs index c91ea723..8456eccf 100755 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -62,7 +62,7 @@ impl ListState { /// let state = ListState::default().with_offset(1); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn with_offset(mut self, offset: usize) -> Self { + pub const fn with_offset(mut self, offset: usize) -> Self { self.offset = offset; self } @@ -78,7 +78,7 @@ impl ListState { /// let state = ListState::default().with_selected(Some(1)); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn with_selected(mut self, selected: Option) -> Self { + pub const fn with_selected(mut self, selected: Option) -> Self { self.selected = selected; self } @@ -92,7 +92,7 @@ impl ListState { /// let state = ListState::default(); /// assert_eq!(state.offset(), 0); /// ``` - pub fn offset(&self) -> usize { + pub const fn offset(&self) -> usize { self.offset } @@ -120,7 +120,7 @@ impl ListState { /// let state = TableState::default(); /// assert_eq!(state.selected(), None); /// ``` - pub fn selected(&self) -> Option { + pub const fn selected(&self) -> Option { self.selected } @@ -594,7 +594,7 @@ impl<'a> List<'a> { /// let list = List::new(items).highlight_symbol(">>"); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn highlight_symbol(mut self, highlight_symbol: &'a str) -> List<'a> { + pub const fn highlight_symbol(mut self, highlight_symbol: &'a str) -> List<'a> { self.highlight_symbol = Some(highlight_symbol); self } @@ -629,7 +629,7 @@ impl<'a> List<'a> { /// /// This is a fluent setter method which must be chained or used as it consumes self #[must_use = "method moves the value of self and returns the modified value"] - pub fn repeat_highlight_symbol(mut self, repeat: bool) -> List<'a> { + pub const fn repeat_highlight_symbol(mut self, repeat: bool) -> List<'a> { self.repeat_highlight_symbol = repeat; self } @@ -660,7 +660,7 @@ impl<'a> List<'a> { /// let list = List::new(items).highlight_spacing(HighlightSpacing::Always); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn highlight_spacing(mut self, value: HighlightSpacing) -> Self { + pub const fn highlight_spacing(mut self, value: HighlightSpacing) -> Self { self.highlight_spacing = value; self } @@ -682,7 +682,7 @@ impl<'a> List<'a> { /// let list = List::new(items).direction(ListDirection::BottomToTop); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn direction(mut self, direction: ListDirection) -> List<'a> { + pub const fn direction(mut self, direction: ListDirection) -> List<'a> { self.direction = direction; self } @@ -701,7 +701,7 @@ impl<'a> List<'a> { /// let list = List::new(items).scroll_padding(1); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn scroll_padding(mut self, padding: usize) -> List<'a> { + pub const fn scroll_padding(mut self, padding: usize) -> List<'a> { self.scroll_padding = padding; self } diff --git a/src/widgets/paragraph.rs b/src/widgets/paragraph.rs index a4fd685d..b3593698 100644 --- a/src/widgets/paragraph.rs +++ b/src/widgets/paragraph.rs @@ -7,7 +7,7 @@ use crate::{ widgets::{reflow::*, Block}, }; -fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment) -> u16 { +const fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment) -> u16 { match alignment { Alignment::Center => (text_area_width / 2).saturating_sub(line_width / 2), Alignment::Right => text_area_width.saturating_sub(line_width), @@ -167,7 +167,7 @@ impl<'a> Paragraph<'a> { /// let paragraph = Paragraph::new("Hello, world!").wrap(Wrap { trim: true }); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn wrap(mut self, wrap: Wrap) -> Paragraph<'a> { + pub const fn wrap(mut self, wrap: Wrap) -> Paragraph<'a> { self.wrap = Some(wrap); self } @@ -184,7 +184,7 @@ impl<'a> Paragraph<'a> { /// For more information about future scrolling design and concerns, see [RFC: Design of /// Scrollable Widgets](https://github.com/ratatui-org/ratatui/issues/174) on GitHub. #[must_use = "method moves the value of self and returns the modified value"] - pub fn scroll(mut self, offset: (Vertical, Horizontal)) -> Paragraph<'a> { + pub const fn scroll(mut self, offset: (Vertical, Horizontal)) -> Paragraph<'a> { self.scroll = offset; self } @@ -201,7 +201,7 @@ impl<'a> Paragraph<'a> { /// let paragraph = Paragraph::new("Hello World").alignment(Alignment::Center); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn alignment(mut self, alignment: Alignment) -> Paragraph<'a> { + pub const fn alignment(mut self, alignment: Alignment) -> Paragraph<'a> { self.alignment = alignment; self } @@ -217,7 +217,7 @@ impl<'a> Paragraph<'a> { /// let paragraph = Paragraph::new("Hello World").left_aligned(); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn left_aligned(self) -> Self { + pub const fn left_aligned(self) -> Self { self.alignment(Alignment::Left) } @@ -232,7 +232,7 @@ impl<'a> Paragraph<'a> { /// let paragraph = Paragraph::new("Hello World").centered(); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn centered(self) -> Self { + pub const fn centered(self) -> Self { self.alignment(Alignment::Center) } @@ -247,7 +247,7 @@ impl<'a> Paragraph<'a> { /// let paragraph = Paragraph::new("Hello World").right_aligned(); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn right_aligned(self) -> Self { + pub const fn right_aligned(self) -> Self { self.alignment(Alignment::Right) } diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index 8f393230..9e10f778 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -105,7 +105,7 @@ impl<'a> Sparkline<'a> { /// # } /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn data(mut self, data: &'a [u64]) -> Sparkline<'a> { + pub const fn data(mut self, data: &'a [u64]) -> Sparkline<'a> { self.data = data; self } @@ -115,7 +115,7 @@ impl<'a> Sparkline<'a> { /// Every bar will be scaled accordingly. If no max is given, this will be the max in the /// dataset. #[must_use = "method moves the value of self and returns the modified value"] - pub fn max(mut self, max: u64) -> Sparkline<'a> { + pub const fn max(mut self, max: u64) -> Sparkline<'a> { self.max = Some(max); self } @@ -125,7 +125,7 @@ impl<'a> Sparkline<'a> { /// Can be [`symbols::bar::THREE_LEVELS`], [`symbols::bar::NINE_LEVELS`] (default) or a custom /// [`Set`](symbols::bar::Set). #[must_use = "method moves the value of self and returns the modified value"] - pub fn bar_set(mut self, bar_set: symbols::bar::Set) -> Sparkline<'a> { + pub const fn bar_set(mut self, bar_set: symbols::bar::Set) -> Sparkline<'a> { self.bar_set = bar_set; self } @@ -134,7 +134,7 @@ impl<'a> Sparkline<'a> { /// /// [`RenderDirection::LeftToRight`] by default. #[must_use = "method moves the value of self and returns the modified value"] - pub fn direction(mut self, direction: RenderDirection) -> Sparkline<'a> { + pub const fn direction(mut self, direction: RenderDirection) -> Sparkline<'a> { self.direction = direction; self } diff --git a/src/widgets/table/highlight_spacing.rs b/src/widgets/table/highlight_spacing.rs index d8c7e82e..87be9b89 100644 --- a/src/widgets/table/highlight_spacing.rs +++ b/src/widgets/table/highlight_spacing.rs @@ -29,7 +29,7 @@ impl HighlightSpacing { /// has_selection: true if a row is selected in the table /// /// Returns true if a selection column should be displayed - pub(crate) fn should_add(&self, has_selection: bool) -> bool { + pub(crate) const fn should_add(&self, has_selection: bool) -> bool { match self { HighlightSpacing::Always => true, HighlightSpacing::WhenSelected => has_selection, diff --git a/src/widgets/table/row.rs b/src/widgets/table/row.rs index 74ae4d5b..5676d850 100644 --- a/src/widgets/table/row.rs +++ b/src/widgets/table/row.rs @@ -145,7 +145,7 @@ impl<'a> Row<'a> { /// let row = Row::new(cells).height(2); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn height(mut self, height: u16) -> Self { + pub const fn height(mut self, height: u16) -> Self { self.height = height; self } @@ -164,7 +164,7 @@ impl<'a> Row<'a> { /// let row = Row::default().top_margin(1); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn top_margin(mut self, margin: u16) -> Self { + pub const fn top_margin(mut self, margin: u16) -> Self { self.top_margin = margin; self } @@ -183,7 +183,7 @@ impl<'a> Row<'a> { /// let row = Row::default().bottom_margin(1); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn bottom_margin(mut self, margin: u16) -> Self { + pub const fn bottom_margin(mut self, margin: u16) -> Self { self.bottom_margin = margin; self } @@ -224,7 +224,7 @@ impl<'a> Row<'a> { // private methods for rendering impl Row<'_> { /// Returns the total height of the row. - pub(crate) fn height_with_margin(&self) -> u16 { + pub(crate) const fn height_with_margin(&self) -> u16 { self.height .saturating_add(self.top_margin) .saturating_add(self.bottom_margin) diff --git a/src/widgets/table/table.rs b/src/widgets/table/table.rs index 9658c7ad..801e9f45 100644 --- a/src/widgets/table/table.rs +++ b/src/widgets/table/table.rs @@ -400,7 +400,7 @@ impl<'a> Table<'a> { /// let table = Table::new(rows, widths).column_spacing(1); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn column_spacing(mut self, spacing: u16) -> Self { + pub const fn column_spacing(mut self, spacing: u16) -> Self { self.column_spacing = spacing; self } @@ -530,7 +530,7 @@ impl<'a> Table<'a> { /// let table = Table::new(rows, widths).highlight_spacing(HighlightSpacing::Always); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn highlight_spacing(mut self, value: HighlightSpacing) -> Self { + pub const fn highlight_spacing(mut self, value: HighlightSpacing) -> Self { self.highlight_spacing = value; self } diff --git a/src/widgets/table/table_state.rs b/src/widgets/table/table_state.rs index 2be90d1d..5c1aeefe 100644 --- a/src/widgets/table/table_state.rs +++ b/src/widgets/table/table_state.rs @@ -75,7 +75,7 @@ impl TableState { /// let state = TableState::new().with_offset(1); /// ``` #[must_use = "method moves the value of self and returns the modified value"] - pub fn with_offset(mut self, offset: usize) -> Self { + pub const fn with_offset(mut self, offset: usize) -> Self { self.offset = offset; self } @@ -108,7 +108,7 @@ impl TableState { /// let state = TableState::new(); /// assert_eq!(state.offset(), 0); /// ``` - pub fn offset(&self) -> usize { + pub const fn offset(&self) -> usize { self.offset } @@ -136,7 +136,7 @@ impl TableState { /// let state = TableState::new(); /// assert_eq!(state.selected(), None); /// ``` - pub fn selected(&self) -> Option { + pub const fn selected(&self) -> Option { self.selected } diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 837ca215..c81baad8 100755 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -113,7 +113,7 @@ impl<'a> Tabs<'a> { /// The first tab has index 0 (this is also the default index). /// The selected tab can have a different style with [`Tabs::highlight_style`]. #[must_use = "method moves the value of self and returns the modified value"] - pub fn select(mut self, selected: usize) -> Tabs<'a> { + pub const fn select(mut self, selected: usize) -> Tabs<'a> { self.selected = selected; self }