mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-10 07:04:17 +00:00
refactor: clippy::return_self_not_must_use (#974)
This commit is contained in:
parent
3cd4369176
commit
ab951fae81
11 changed files with 23 additions and 0 deletions
|
@ -76,6 +76,7 @@ items_after_statements = "warn"
|
|||
missing_const_for_fn = "warn"
|
||||
needless_for_each = "warn"
|
||||
needless_pass_by_value = "warn"
|
||||
return_self_not_must_use = "warn"
|
||||
semicolon_if_nothing_returned = "warn"
|
||||
trivially_copy_pass_by_ref = "warn"
|
||||
use_self = "warn"
|
||||
|
|
|
@ -391,6 +391,7 @@ impl Layout {
|
|||
/// # use ratatui::layout::{Flex, Layout, Constraint::*};
|
||||
/// let layout = Layout::horizontal([Length(20), Length(20), Length(20)]).flex(Flex::Legacy);
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub const fn flex(mut self, flex: Flex) -> Self {
|
||||
self.flex = flex;
|
||||
self
|
||||
|
@ -415,6 +416,7 @@ impl Layout {
|
|||
///
|
||||
/// - If the layout has only one item, the spacing will not be applied.
|
||||
/// - Spacing will not be applied for [`Flex::SpaceAround`] and [`Flex::SpaceBetween`]
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub const fn spacing(mut self, spacing: u16) -> Self {
|
||||
self.spacing = spacing;
|
||||
self
|
||||
|
|
|
@ -111,6 +111,7 @@ impl Rect {
|
|||
/// Returns a new `Rect` inside the current one, with the given margin on each side.
|
||||
///
|
||||
/// If the margin is larger than the `Rect`, the returned `Rect` will have no area.
|
||||
#[must_use = "method returns the modified value"]
|
||||
pub fn inner(self, margin: &Margin) -> Self {
|
||||
let doubled_margin_horizontal = margin.horizontal.saturating_mul(2);
|
||||
let doubled_margin_vertical = margin.vertical.saturating_mul(2);
|
||||
|
@ -135,6 +136,7 @@ impl Rect {
|
|||
/// - Positive `y` moves the whole `Rect` to the bottom, negative to the top.
|
||||
///
|
||||
/// See [`Offset`] for details.
|
||||
#[must_use = "method returns the modified value"]
|
||||
pub fn offset(self, offset: Offset) -> Self {
|
||||
Self {
|
||||
x: i32::from(self.x)
|
||||
|
@ -148,6 +150,7 @@ impl Rect {
|
|||
}
|
||||
|
||||
/// Returns a new `Rect` that contains both the current one and the given one.
|
||||
#[must_use = "method returns the modified value"]
|
||||
pub fn union(self, other: Self) -> Self {
|
||||
let x1 = min(self.x, other.x);
|
||||
let y1 = min(self.y, other.y);
|
||||
|
@ -164,6 +167,7 @@ impl Rect {
|
|||
/// Returns a new `Rect` that is the intersection of the current one and the given one.
|
||||
///
|
||||
/// If the two `Rect`s do not intersect, the returned `Rect` will have no area.
|
||||
#[must_use = "method returns the modified value"]
|
||||
pub fn intersection(self, other: Self) -> Self {
|
||||
let x1 = max(self.x, other.x);
|
||||
let y1 = max(self.y, other.y);
|
||||
|
@ -227,6 +231,7 @@ impl Rect {
|
|||
/// let rect = Rect::new(0, 0, 100, 100).clamp(area);
|
||||
/// # }
|
||||
/// ```
|
||||
#[must_use = "method returns the modified value"]
|
||||
pub fn clamp(self, other: Self) -> Self {
|
||||
let width = self.width.min(other.width);
|
||||
let height = self.height.min(other.height);
|
||||
|
|
|
@ -118,6 +118,7 @@ impl<'a> BarChart<'a> {
|
|||
/// .data(&[("B0", 0), ("B1", 2), ("B2", 4), ("B3", 3)])
|
||||
/// .data(BarGroup::default().bars(&[Bar::default().value(10), Bar::default().value(20)]));
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn data(mut self, data: impl Into<BarGroup<'a>>) -> BarChart<'a> {
|
||||
let group: BarGroup = data.into();
|
||||
if !group.bars.is_empty() {
|
||||
|
|
|
@ -234,6 +234,7 @@ impl<'a> Block<'a> {
|
|||
/// - [`Block::title_style`]
|
||||
/// - [`Block::title_alignment`]
|
||||
/// - [`Block::title_position`]
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn title<T>(mut self, title: T) -> Block<'a>
|
||||
where
|
||||
T: Into<Title<'a>>,
|
||||
|
|
|
@ -87,6 +87,7 @@ pub enum Position {
|
|||
|
||||
impl<'a> Title<'a> {
|
||||
/// Set the title content.
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn content<T>(mut self, content: T) -> Title<'a>
|
||||
where
|
||||
T: Into<Line<'a>>,
|
||||
|
|
|
@ -46,6 +46,7 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
|
|||
///
|
||||
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
|
||||
/// your own type that implements [`Into<Style>`]).
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn show_surrounding<S: Into<Style>>(mut self, style: S) -> Self {
|
||||
self.show_surrounding = Some(style.into());
|
||||
self
|
||||
|
@ -55,6 +56,7 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
|
|||
///
|
||||
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
|
||||
/// your own type that implements [`Into<Style>`]).
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn show_weekdays_header<S: Into<Style>>(mut self, style: S) -> Self {
|
||||
self.show_weekday = Some(style.into());
|
||||
self
|
||||
|
@ -64,6 +66,7 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
|
|||
///
|
||||
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
|
||||
/// your own type that implements [`Into<Style>`]).
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn show_month_header<S: Into<Style>>(mut self, style: S) -> Self {
|
||||
self.show_month = Some(style.into());
|
||||
self
|
||||
|
@ -73,12 +76,14 @@ impl<'a, DS: DateStyler> Monthly<'a, DS> {
|
|||
///
|
||||
/// `style` accepts any type that is convertible to [`Style`] (e.g. [`Style`], [`Color`], or
|
||||
/// your own type that implements [`Into<Style>`]).
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn default_style<S: Into<Style>>(mut self, style: S) -> Self {
|
||||
self.default_style = style.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Render the calendar within a [Block]
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn block(mut self, block: Block<'a>) -> Self {
|
||||
self.block = Some(block);
|
||||
self
|
||||
|
|
|
@ -744,6 +744,7 @@ where
|
|||
/// .marker(symbols::Marker::Block)
|
||||
/// .paint(|ctx| {});
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub const fn marker(mut self, marker: symbols::Marker) -> Canvas<'a, F> {
|
||||
self.marker = marker;
|
||||
self
|
||||
|
|
|
@ -316,6 +316,7 @@ impl<'a> LineGauge<'a> {
|
|||
///
|
||||
/// With `LineGauge`, labels are only on the left, see [`Gauge`] for a centered label.
|
||||
/// If the label is not defined, it is the percentage filled.
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn label<T>(mut self, label: T) -> Self
|
||||
where
|
||||
T: Into<Line<'a>>,
|
||||
|
|
|
@ -557,6 +557,7 @@ impl<'a> Table<'a> {
|
|||
/// ];
|
||||
/// let table = Table::new(Vec::<Row>::new(), widths).flex(Flex::Legacy);
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub const fn flex(mut self, flex: Flex) -> Self {
|
||||
self.flex = flex;
|
||||
self
|
||||
|
|
|
@ -160,6 +160,7 @@ impl<'a> Tabs<'a> {
|
|||
/// # use ratatui::{prelude::*, widgets::Tabs};
|
||||
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).divider("-");
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn divider<T>(mut self, divider: T) -> Tabs<'a>
|
||||
where
|
||||
T: Into<Span<'a>>,
|
||||
|
@ -184,6 +185,7 @@ impl<'a> Tabs<'a> {
|
|||
/// # use ratatui::{prelude::*, widgets::Tabs};
|
||||
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).padding("", "");
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn padding<T, U>(mut self, left: T, right: U) -> Tabs<'a>
|
||||
where
|
||||
T: Into<Line<'a>>,
|
||||
|
@ -205,6 +207,7 @@ impl<'a> Tabs<'a> {
|
|||
/// # use ratatui::{prelude::*, widgets::Tabs};
|
||||
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).padding_left("->");
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn padding_left<T>(mut self, padding: T) -> Tabs<'a>
|
||||
where
|
||||
T: Into<Line<'a>>,
|
||||
|
@ -224,6 +227,7 @@ impl<'a> Tabs<'a> {
|
|||
/// # use ratatui::{prelude::*, widgets::Tabs};
|
||||
/// let tabs = Tabs::new(vec!["Tab 1", "Tab 2"]).padding_right("<-");
|
||||
/// ```
|
||||
#[must_use = "method moves the value of self and returns the modified value"]
|
||||
pub fn padding_right<T>(mut self, padding: T) -> Tabs<'a>
|
||||
where
|
||||
T: Into<Line<'a>>,
|
||||
|
|
Loading…
Reference in a new issue