From ce534964d1021a5becfa4749d0bc391fe3dcaf97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 3 Jun 2021 22:11:54 +0200 Subject: [PATCH 1/2] Pacify clippy --- src/alignment/mod.rs | 6 +++--- src/rendering/cursor.rs | 16 +--------------- src/style/height_mode.rs | 4 ++-- src/style/vertical_overdraw.rs | 2 +- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/alignment/mod.rs b/src/alignment/mod.rs index 8c8aac1b..f8e9a85d 100644 --- a/src/alignment/mod.rs +++ b/src/alignment/mod.rs @@ -39,7 +39,7 @@ impl HorizontalAlignment { } /// Calculate offset from the left side and whitespace information. - pub fn place_line( + pub(crate) fn place_line( self, line: &str, renderer: &impl TextRenderer, @@ -113,10 +113,10 @@ pub enum VerticalAlignment { impl VerticalAlignment { /// Set the cursor's initial vertical position - pub fn apply_vertical_alignment<'a, 'b, S>( + pub(crate) fn apply_vertical_alignment<'a, S>( self, cursor: &mut Cursor, - styled_text_box: &'b TextBox<'a, S>, + styled_text_box: &TextBox<'a, S>, ) where S: TextRenderer, { diff --git a/src/rendering/cursor.rs b/src/rendering/cursor.rs index 07dfca91..db87d7dc 100644 --- a/src/rendering/cursor.rs +++ b/src/rendering/cursor.rs @@ -28,41 +28,27 @@ impl LineCursor { } /// Returns the distance to the next tab position. - #[inline] pub fn next_tab_width(&self) -> u32 { let next_tab_pos = (self.position / self.tab_width + 1) * self.tab_width; next_tab_pos - self.position } - /// Returns the width of the textbox - #[inline] - #[must_use] + /// Returns the width of the text box. pub fn line_width(&self) -> u32 { self.width } - /// Moves the cursor back to the start of the line. - #[inline] - pub fn carriage_return(&mut self) { - self.position = 0; - } - /// Returns whether the current line has enough space to also include an object of given width. - #[inline] - #[must_use] pub fn fits_in_line(&self, width: u32) -> bool { width <= self.space() } /// Returns the amount of empty space in the line. - #[inline] - #[must_use] pub fn space(&self) -> u32 { self.width - self.position } /// Moves the cursor by a given amount. - #[inline] pub fn move_cursor(&mut self, by: i32) -> Result { if by < 0 { let abs = by.abs() as u32; diff --git a/src/style/height_mode.rs b/src/style/height_mode.rs index 4769e47e..77f1334f 100644 --- a/src/style/height_mode.rs +++ b/src/style/height_mode.rs @@ -196,7 +196,7 @@ impl HeightMode { /// Apply the height mode to the text box. /// /// *Note:* This function normally does not need to be called manually. - pub fn apply(self, text_box: &mut TextBox<'_, F>) + pub(crate) fn apply(self, text_box: &mut TextBox<'_, F>) where F: TextRenderer, { @@ -216,7 +216,7 @@ impl HeightMode { /// If a line does not fully fit in the bounding box, some `HeightMode` options allow drawing /// partial lines. For a partial line, this function calculates, which rows of each character /// should be displayed. - pub fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range { + pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range { let overdraw = match self { HeightMode::Exact(overdraw) | HeightMode::ShrinkToText(overdraw) => overdraw, HeightMode::FitToText => VerticalOverdraw::Visible, diff --git a/src/style/vertical_overdraw.rs b/src/style/vertical_overdraw.rs index 45675728..9893d594 100644 --- a/src/style/vertical_overdraw.rs +++ b/src/style/vertical_overdraw.rs @@ -15,7 +15,7 @@ pub enum VerticalOverdraw { impl VerticalOverdraw { /// Calculate the range of rows of the current line that can be drawn. - pub fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range { + pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range { match self { VerticalOverdraw::FullRowsOnly => { if cursor.in_display_area() { From ac6a4ee176be4e5b9d321be6efb1b006d09d484e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 3 Jun 2021 22:16:52 +0200 Subject: [PATCH 2/2] Clean up must_use and inline attributes --- src/lib.rs | 7 +------ src/parser/mod.rs | 1 + src/rendering/cursor.rs | 3 +-- src/rendering/line.rs | 1 - src/rendering/line_iter.rs | 2 +- src/style/builder.rs | 9 +-------- src/style/mod.rs | 3 ++- 7 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d4c74ac..c29a1455 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,6 +140,7 @@ use embedded_graphics::{ /// [module-level documentation]: index.html /// [`draw`]: #method.draw #[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[must_use] pub struct TextBox<'a, S> { /// The text to be displayed in this `TextBox` pub text: &'a str, @@ -163,7 +164,6 @@ where { /// Creates a new `TextBox` instance with a given bounding `Rectangle`. #[inline] - #[must_use] pub fn new(text: &'a str, bounds: Rectangle, character_style: S) -> Self { TextBox::with_textbox_style(text, bounds, character_style, TextBoxStyle::default()) } @@ -175,7 +175,6 @@ where { /// Creates a new `TextBox` instance with a given bounding `Rectangle` and a given `TextBoxStyle`. #[inline] - #[must_use] pub fn with_textbox_style( text: &'a str, bounds: Rectangle, @@ -197,7 +196,6 @@ where /// Creates a new `TextBox` instance with a given bounding `Rectangle` and a given `TextBoxStyle`. #[inline] - #[must_use] pub fn with_alignment( text: &'a str, bounds: Rectangle, @@ -214,7 +212,6 @@ where /// Creates a new `TextBox` instance with a given bounding `Rectangle` and a given `TextBoxStyle`. #[inline] - #[must_use] pub fn with_vertical_alignment( text: &'a str, bounds: Rectangle, @@ -242,7 +239,6 @@ where Self: Clone, { #[inline] - #[must_use] fn translate(&self, by: Point) -> Self { Self { bounds: self.bounds.translate(by), @@ -260,7 +256,6 @@ where impl Dimensions for TextBox<'_, S> { #[inline] - #[must_use] fn bounding_box(&self) -> Rectangle { self.bounds } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index dd5a19ab..74792f2b 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -76,6 +76,7 @@ impl<'a> Parser<'a> { /// Create a new parser object to process the given piece of text. #[inline] #[must_use] + pub fn parse(text: &'a str) -> Self { Self { inner: text.chars(), diff --git a/src/rendering/cursor.rs b/src/rendering/cursor.rs index db87d7dc..b42cd75f 100644 --- a/src/rendering/cursor.rs +++ b/src/rendering/cursor.rs @@ -106,6 +106,7 @@ impl Cursor { } } + #[must_use] pub fn line(&self) -> LineCursor { LineCursor { start: Point::new(self.bounds.top_left.x, self.y), @@ -129,14 +130,12 @@ impl Cursor { /// Returns the width of the text box. #[inline] - #[must_use] pub fn line_width(&self) -> u32 { self.bounds.size.width } /// Returns the height of a line. #[inline] - #[must_use] pub fn line_height(&self) -> i32 { self.line_height } diff --git a/src/rendering/line.rs b/src/rendering/line.rs index f6a918ce..f42730c0 100644 --- a/src/rendering/line.rs +++ b/src/rendering/line.rs @@ -59,7 +59,6 @@ where ::Color: From, { /// Creates a new line renderer. - #[inline] pub fn new(cursor: LineCursor, state: LineRenderState<'a, F>) -> Self { Self { cursor, state } } diff --git a/src/rendering/line_iter.rs b/src/rendering/line_iter.rs index 74a1da9f..3e58a0d4 100644 --- a/src/rendering/line_iter.rs +++ b/src/rendering/line_iter.rs @@ -19,6 +19,7 @@ use as_slice::AsSlice; /// Parser to break down a line into primitive elements used by measurement and rendering. #[derive(Debug)] +#[must_use] pub struct LineElementParser<'a, 'b> { /// Position information. cursor: LineCursor, @@ -63,7 +64,6 @@ pub trait ElementHandler { impl<'a, 'b> LineElementParser<'a, 'b> { /// Creates a new element parser. #[inline] - #[must_use] pub fn new( parser: &'b mut Parser<'a>, cursor: LineCursor, diff --git a/src/style/builder.rs b/src/style/builder.rs index e3b0c5b8..b0c851af 100644 --- a/src/style/builder.rs +++ b/src/style/builder.rs @@ -10,6 +10,7 @@ use crate::{ /// /// [`TextBoxStyle`]: struct.TextBoxStyle.html #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[must_use] pub struct TextBoxStyleBuilder { style: TextBoxStyle, } @@ -24,7 +25,6 @@ impl Default for TextBoxStyleBuilder { impl TextBoxStyleBuilder { /// Creates a new text box style builder object. #[inline] - #[must_use] pub const fn new() -> Self { Self { style: TextBoxStyle { @@ -54,7 +54,6 @@ impl TextBoxStyleBuilder { /// .build(); /// ``` #[inline] - #[must_use] pub const fn line_height(mut self, line_height: LineHeight) -> Self { self.style.line_height = line_height; @@ -74,7 +73,6 @@ impl TextBoxStyleBuilder { /// .build(); /// ``` #[inline] - #[must_use] pub const fn paragraph_spacing(mut self, paragraph_spacing: u32) -> Self { self.style.paragraph_spacing = paragraph_spacing; @@ -83,7 +81,6 @@ impl TextBoxStyleBuilder { /// Sets the horizontal text alignment. #[inline] - #[must_use] pub const fn alignment(mut self, alignment: HorizontalAlignment) -> TextBoxStyleBuilder { self.style.alignment = alignment; @@ -92,7 +89,6 @@ impl TextBoxStyleBuilder { /// Sets the vertical text alignment. #[inline] - #[must_use] pub const fn vertical_alignment( mut self, vertical_alignment: VerticalAlignment, @@ -104,7 +100,6 @@ impl TextBoxStyleBuilder { /// Sets the height mode. #[inline] - #[must_use] pub const fn height_mode(mut self, height_mode: HeightMode) -> TextBoxStyleBuilder { self.style.height_mode = height_mode; @@ -113,7 +108,6 @@ impl TextBoxStyleBuilder { /// Sets the tab size. #[inline] - #[must_use] pub const fn tab_size(mut self, tab_size: TabSize) -> Self { self.style.tab_size = tab_size; @@ -124,7 +118,6 @@ impl TextBoxStyleBuilder { /// /// [`TextBoxStyle`]: struct.TextBoxStyle.html #[inline] - #[must_use] pub const fn build(self) -> TextBoxStyle { self.style } diff --git a/src/style/mod.rs b/src/style/mod.rs index 919c50ac..c98d227c 100644 --- a/src/style/mod.rs +++ b/src/style/mod.rs @@ -207,6 +207,7 @@ impl TabSize { /// [`from_text_style`]: #method.from_text_style #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] #[non_exhaustive] +#[must_use] pub struct TextBoxStyle { /// Horizontal text alignment. pub alignment: HorizontalAlignment, @@ -252,6 +253,7 @@ impl Default for TextBoxStyle { /// Information about a line. #[derive(Debug)] +#[must_use] pub struct LineMeasurement { /// Maximum line width in pixels. pub max_line_width: u32, @@ -306,7 +308,6 @@ impl TextBoxStyle { /// processing a token. If a token opens a new line, it will be returned as the carried token. /// If the carried token is `None`, the parser has finished processing the text. #[inline] - #[must_use] pub(crate) fn measure_line<'a, S>( &self, character_style: &S,