diff --git a/examples/announce.rs b/examples/announce.rs index 216a40e..25626a4 100644 --- a/examples/announce.rs +++ b/examples/announce.rs @@ -1,7 +1,10 @@ //! An example for how to send text to the display. use clap::Parser; -use servicepoint::*; +use servicepoint::{ + CharGrid, CharGridCommand, ClearCommand, Connection, Origin, UdpConnection, + TILE_WIDTH, +}; #[derive(Parser, Debug)] struct Cli { diff --git a/examples/brightness_tester.rs b/examples/brightness_tester.rs index ee39209..b743f48 100644 --- a/examples/brightness_tester.rs +++ b/examples/brightness_tester.rs @@ -1,7 +1,11 @@ //! Show a brightness level test pattern on screen use clap::Parser; -use servicepoint::*; +use servicepoint::{ + Bitmap, BitmapCommand, Brightness, BrightnessGrid, BrightnessGridCommand, + CompressionCode, Connection, DataRef, Grid, Origin, UdpConnection, + TILE_HEIGHT, TILE_WIDTH, +}; #[derive(Parser, Debug)] struct Cli { diff --git a/examples/moving_line.rs b/examples/moving_line.rs index 29507b3..53024b2 100644 --- a/examples/moving_line.rs +++ b/examples/moving_line.rs @@ -1,7 +1,10 @@ //! A simple example for how to send pixel data to the display. use clap::Parser; -use servicepoint::*; +use servicepoint::{ + Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin, + UdpConnection, FRAME_PACING, PIXEL_HEIGHT, PIXEL_WIDTH, +}; use std::thread; #[derive(Parser, Debug)] diff --git a/examples/wiping_clear.rs b/examples/wiping_clear.rs index 76a2c33..e4e1d84 100644 --- a/examples/wiping_clear.rs +++ b/examples/wiping_clear.rs @@ -1,7 +1,10 @@ //! An example on how to modify the image on screen without knowing the current content. use clap::Parser; -use servicepoint::*; +use servicepoint::{ + Bitmap, BitmapCommand, CompressionCode, Connection, Grid, Origin, + UdpConnection, FRAME_PACING, PIXEL_HEIGHT, PIXEL_WIDTH, +}; use std::thread; use std::time::Duration; diff --git a/src/commands/bitmap.rs b/src/commands/bitmap.rs index d065d42..3b8b0d4 100644 --- a/src/commands/bitmap.rs +++ b/src/commands/bitmap.rs @@ -205,14 +205,17 @@ mod tests { } = p; // mangle it - for byte in payload.iter_mut() { + for byte in &mut payload { *byte -= *byte / 2; } let p = Packet { header, payload }; let result = TypedCommand::try_from(p); if *compression != CompressionCode::Uncompressed { - assert_eq!(result, Err(TryFromPacketError::DecompressionFailed)) + assert_eq!( + result, + Err(TryFromPacketError::DecompressionFailed) + ); } else { assert!(result.is_ok()); } diff --git a/src/commands/bitvec.rs b/src/commands/bitvec.rs index d5436e1..be4e703 100644 --- a/src/commands/bitvec.rs +++ b/src/commands/bitvec.rs @@ -27,9 +27,9 @@ pub enum BinaryOperation { /// /// `new_bit = old_bit op sent_bit` /// -/// For example, [BinaryOperation::Or] can be used to turn on some pixels without affecting other pixels. +/// For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels. /// -/// The contained [BitVec] is always uncompressed. +/// The contained [`BitVec`] is always uncompressed. #[derive(Clone, PartialEq, Debug, Eq)] pub struct BitVecCommand { /// the pixels to send to the display as one long row @@ -87,7 +87,7 @@ impl TryFrom for BitVecCommand { payload, } = packet; let command_code = CommandCode::try_from(command_code) - .map_err(|_| TryFromPacketError::InvalidCommand(command_code))?; + .map_err(|()| TryFromPacketError::InvalidCommand(command_code))?; let operation = match command_code { CommandCode::BitmapLinear => BinaryOperation::Overwrite, CommandCode::BitmapLinearAnd => BinaryOperation::And, @@ -205,14 +205,17 @@ mod tests { } = p; // mangle it - for byte in payload.iter_mut() { + for byte in &mut payload { *byte -= *byte / 2; } let p = Packet { header, payload }; let result = TypedCommand::try_from(p); if *compression != CompressionCode::Uncompressed { - assert_eq!(result, Err(TryFromPacketError::DecompressionFailed)) + assert_eq!( + result, + Err(TryFromPacketError::DecompressionFailed) + ); } else { // when not compressing, there is no way to detect corrupted data assert!(result.is_ok()); diff --git a/src/commands/brightness.rs b/src/commands/brightness.rs index 876a28a..b06a6b4 100644 --- a/src/commands/brightness.rs +++ b/src/commands/brightness.rs @@ -101,7 +101,7 @@ mod tests { brightness: Brightness::MAX }, Brightness::MAX.into() - ) + ); } #[test] @@ -130,7 +130,7 @@ mod tests { assert!(matches!( result, Err(TryFromPacketError::ExtraneousHeaderValues) - )) + )); } #[test] diff --git a/src/commands/clear.rs b/src/commands/clear.rs index b7f1b5b..8e8435e 100644 --- a/src/commands/clear.rs +++ b/src/commands/clear.rs @@ -69,7 +69,7 @@ mod tests { assert!(matches!( result, Err(TryFromPacketError::ExtraneousHeaderValues) - )) + )); } #[test] diff --git a/src/commands/errors.rs b/src/commands/errors.rs index 531eac6..28bee56 100644 --- a/src/commands/errors.rs +++ b/src/commands/errors.rs @@ -1,7 +1,7 @@ use crate::LoadBitmapError; use std::num::TryFromIntError; -/// Err values for [crate::TypedCommand::try_from]. +/// Err values for [`crate::TypedCommand::try_from`]. #[derive(Debug, PartialEq, thiserror::Error)] pub enum TryFromPacketError { /// the contained command code does not correspond to a known command diff --git a/src/commands/fade_out.rs b/src/commands/fade_out.rs index fd03aa6..046d55b 100644 --- a/src/commands/fade_out.rs +++ b/src/commands/fade_out.rs @@ -47,7 +47,7 @@ mod tests { use crate::command_code::CommandCode; use crate::commands::errors::TryFromPacketError; use crate::commands::tests::{round_trip, TestImplementsCommand}; - use crate::{ClearCommand, FadeOutCommand, Header, Packet, TypedCommand}; + use crate::{FadeOutCommand, Header, Packet, TypedCommand}; impl TestImplementsCommand for FadeOutCommand {} @@ -72,7 +72,7 @@ mod tests { assert!(matches!( result, Err(TryFromPacketError::ExtraneousHeaderValues) - )) + )); } #[test] @@ -91,6 +91,6 @@ mod tests { assert!(matches!( result, Err(TryFromPacketError::UnexpectedPayloadSize(0, 2)) - )) + )); } } diff --git a/src/commands/hard_reset.rs b/src/commands/hard_reset.rs index ba1d855..248b51d 100644 --- a/src/commands/hard_reset.rs +++ b/src/commands/hard_reset.rs @@ -72,6 +72,6 @@ mod test { assert!(matches!( result, Err(TryFromPacketError::ExtraneousHeaderValues) - )) + )); } } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 091c8dc..701128d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -12,7 +12,7 @@ mod hard_reset; mod typed; use crate::command_code::CommandCode; -use crate::*; +use crate::{Header, Packet}; use std::fmt::Debug; pub use bitmap::*; @@ -34,20 +34,20 @@ pub use typed::*; /// /// # Available commands /// -/// To send text, take a look at [Cp437GridCommand]. +/// To send text, take a look at [`Cp437GridCommand`]. /// -/// To draw pixels, the easiest command to use is [BitmapCommand]. +/// To draw pixels, the easiest command to use is [`BitmapCommand`]. /// /// The other BitmapLinear-Commands operate on a region of pixel memory directly. -/// [BitVecCommand] overwrites a region. -/// [BitmapLinearOr], [BitmapLinearAnd] and [BitmapLinearXor] apply logical operations per pixel. +/// [`BitVecCommand`] overwrites a region. +/// [`BitmapLinearOr`], [`BitmapLinearAnd`] and [`BitmapLinearXor`] apply logical operations per pixel. /// /// Out of bounds operations may be truncated or ignored by the display. /// /// # Compression /// /// Some commands can contain compressed payloads. -/// To get started, use [CompressionCode::default]. +/// To get started, use [`CompressionCode::default`]. /// /// If you want to archive the best performance (e.g. latency), /// you can try the different compression algorithms for your hardware and use case. diff --git a/src/commands/typed.rs b/src/commands/typed.rs index 434915a..1da86cf 100644 --- a/src/commands/typed.rs +++ b/src/commands/typed.rs @@ -141,6 +141,6 @@ mod tests { assert!(matches!( result, Err(TryFromPacketError::InvalidCommand(0xFF)) - )) + )); } } diff --git a/src/connections/fake.rs b/src/connections/fake.rs index dac14f5..46b1354 100644 --- a/src/connections/fake.rs +++ b/src/connections/fake.rs @@ -37,6 +37,6 @@ mod tests { fn send_fake() { let data: &[u8] = &[0u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; let packet = Packet::try_from(data).unwrap(); - FakeConnection.send(packet).unwrap() + FakeConnection.send(packet).unwrap(); } } diff --git a/src/connections/udp.rs b/src/connections/udp.rs index cd3239f..7743756 100644 --- a/src/connections/udp.rs +++ b/src/connections/udp.rs @@ -5,7 +5,7 @@ use std::{error::Error, fmt::Debug, net::UdpSocket}; /// /// Use this when sending commands directly to the display. /// -/// Requires the feature "protocol_udp" which is enabled by default. +/// Requires the feature "`protocol_udp`" which is enabled by default. #[derive(Debug)] pub struct UdpConnection { socket: UdpSocket, diff --git a/src/containers/bit_vec.rs b/src/containers/bit_vec.rs index 2ece813..3bda0de 100644 --- a/src/containers/bit_vec.rs +++ b/src/containers/bit_vec.rs @@ -1,7 +1,7 @@ /// A byte-packed vector of booleans. /// /// The implementation is provided by [bitvec]. -/// This is an alias for the specific type of [bitvec::BitVec] used in this crate. +/// This is an alias for the specific type of [`bitvec::BitVec`] used in this crate. pub type BitVec = bitvec::BitVec; pub mod bitvec { diff --git a/src/containers/bitmap.rs b/src/containers/bitmap.rs index ed1bd7a..46184d3 100644 --- a/src/containers/bitmap.rs +++ b/src/containers/bitmap.rs @@ -1,4 +1,4 @@ -use crate::*; +use crate::{BitVec, DataRef, Grid, ValueGrid, PIXEL_HEIGHT, PIXEL_WIDTH}; use ::bitvec::{order::Msb0, prelude::BitSlice, slice::IterMut}; /// A fixed-size 2D grid of booleans. @@ -25,7 +25,7 @@ impl Bitmap { /// Creates a new [Bitmap] with the specified dimensions. /// The initial state of the contained pixels is false. /// - /// The width has to be a multiple of [TILE_SIZE], otherwise this function returns None. + /// The width has to be a multiple of [`TILE_SIZE`], otherwise this function returns None. /// /// # Arguments /// @@ -86,7 +86,7 @@ impl Bitmap { }) } - /// Creates a [Bitmap] with the specified width from the provided [BitVec] without copying it. + /// Creates a [Bitmap] with the specified width from the provided [`BitVec`] without copying it. /// /// The data cannot be loaded on the following cases: /// - when the data size is not divisible by the width (incomplete rows) @@ -182,7 +182,7 @@ impl Grid for Bitmap { /// When accessing `x` or `y` out of bounds. fn set(&mut self, x: usize, y: usize, value: bool) { self.assert_in_bounds(x, y); - self.bit_vec.set(x + y * self.width, value) + self.bit_vec.set(x + y * self.width, value); } fn get(&self, x: usize, y: usize) -> bool { @@ -227,7 +227,7 @@ impl From for Vec { } impl From for BitVec { - /// Turns a [Bitmap] into the underlying [BitVec]. + /// Turns a [Bitmap] into the underlying [`BitVec`]. fn from(value: Bitmap) -> Self { value.bit_vec } @@ -358,7 +358,7 @@ mod tests { #[test] fn iter() { let grid = Bitmap::new(8, 2).unwrap(); - assert_eq!(16, grid.iter().count()) + assert_eq!(16, grid.iter().count()); } #[test] @@ -415,7 +415,7 @@ mod tests { assert_eq!( Bitmap::load(7, 3, &data), Err(LoadBitmapError::InvalidWidth) - ) + ); } #[test] @@ -424,7 +424,7 @@ mod tests { assert_eq!( Bitmap::load(8, 3, &data), Err(LoadBitmapError::InvalidDataSize) - ) + ); } #[test] @@ -433,7 +433,7 @@ mod tests { assert_eq!( Bitmap::from_bitvec(7, data), Err(LoadBitmapError::InvalidWidth) - ) + ); } #[test] @@ -442,7 +442,7 @@ mod tests { assert_eq!( Bitmap::from_bitvec(8, data), Err(LoadBitmapError::InvalidDataSize) - ) + ); } #[test] @@ -453,6 +453,6 @@ mod tests { #[test] fn new_invalid_width() { - assert_eq!(Bitmap::new(7, 2), None) + assert_eq!(Bitmap::new(7, 2), None); } } diff --git a/src/containers/brightness_grid.rs b/src/containers/brightness_grid.rs index 4f8dab0..0d17582 100644 --- a/src/containers/brightness_grid.rs +++ b/src/containers/brightness_grid.rs @@ -19,7 +19,8 @@ use crate::{Brightness, ByteGrid, Grid, ValueGrid}; pub type BrightnessGrid = ValueGrid; impl BrightnessGrid { - /// Like [Self::load], but ignoring any out-of-range brightness values + /// Like [`Self::load`], but ignoring any out-of-range brightness values + #[must_use] pub fn saturating_load( width: usize, height: usize, diff --git a/src/containers/byte_grid.rs b/src/containers/byte_grid.rs index 0a7fdae..5f8c98a 100644 --- a/src/containers/byte_grid.rs +++ b/src/containers/byte_grid.rs @@ -1,4 +1,4 @@ use crate::ValueGrid; -/// A 2d grid of bytes - see [ValueGrid]. +/// A 2d grid of bytes - see [`ValueGrid`]. pub type ByteGrid = ValueGrid; diff --git a/src/containers/char_grid.rs b/src/containers/char_grid.rs index a7d722b..7bdec95 100644 --- a/src/containers/char_grid.rs +++ b/src/containers/char_grid.rs @@ -3,9 +3,9 @@ use std::string::FromUtf8Error; /// A grid containing UTF-8 characters. /// -/// To send a CharGrid to the display, use a [crate::CharGridCommand]. +/// To send a `CharGrid` to the display, use a [`crate::CharGridCommand`]. /// -/// Also see [ValueGrid] for the non-specialized operations and examples. +/// Also see [`ValueGrid`] for the non-specialized operations and examples. /// /// # Examples /// @@ -21,11 +21,11 @@ use std::string::FromUtf8Error; pub type CharGrid = ValueGrid; impl CharGrid { - /// Loads a [CharGrid] with the specified width from the provided text, wrapping to as many rows as needed. + /// Loads a [`CharGrid`] with the specified width from the provided text, wrapping to as many rows as needed. /// /// The passed rows are extended with '\0' if needed. /// - /// returns: [CharGrid] that contains a copy of the provided data. + /// returns: [`CharGrid`] that contains a copy of the provided data. /// /// # Examples /// @@ -54,7 +54,7 @@ impl CharGrid { for (row, text_line) in lines.iter().enumerate() { #[allow(clippy::unwrap_used)] // we calculated the width before setting - result.set_row_str(row, text_line).unwrap() + result.set_row_str(row, text_line).unwrap(); } result } @@ -70,6 +70,7 @@ impl CharGrid { /// let grid = CharGrid::from("ab\ncd"); /// let col = grid.get_col_str(0).unwrap(); // "ac" /// ``` + #[must_use] pub fn get_col_str(&self, x: usize) -> Option { Some(String::from_iter(self.get_col(x)?)) } @@ -85,13 +86,14 @@ impl CharGrid { /// let grid = CharGrid::from("ab\ncd"); /// let row = grid.get_row_str(0).unwrap(); // "ab" /// ``` + #[must_use] pub fn get_row_str(&self, y: usize) -> Option { Some(String::from_iter(self.get_row(y)?)) } /// Overwrites a row in the grid with a str. /// - /// Returns [SetValueSeriesError] if y is out of bounds or `row` is not of the correct size. + /// Returns [`SetValueSeriesError`] if y is out of bounds or `row` is not of the correct size. /// /// # Examples /// @@ -110,7 +112,7 @@ impl CharGrid { /// Overwrites a column in the grid with a str. /// - /// Returns [SetValueSeriesError] if y is out of bounds or `row` is not of the correct size. + /// Returns [`SetValueSeriesError`] if y is out of bounds or `row` is not of the correct size. /// /// # Examples /// @@ -127,9 +129,9 @@ impl CharGrid { self.set_col(x, value.chars().collect::>().as_ref()) } - /// Loads a [CharGrid] with the specified dimensions from the provided UTF-8 bytes. + /// Loads a [`CharGrid`] with the specified dimensions from the provided UTF-8 bytes. /// - /// returns: [CharGrid] that contains the provided data, or [FromUtf8Error] if the data is invalid. + /// returns: [`CharGrid`] that contains the provided data, or [`FromUtf8Error`] if the data is invalid. /// /// # Examples /// @@ -193,7 +195,7 @@ impl From for String { } impl From<&CharGrid> for String { - /// Converts a [CharGrid] into a [String]. + /// Converts a [`CharGrid`] into a [String]. /// /// Rows are separated by '\n'. /// @@ -215,7 +217,7 @@ impl From<&CharGrid> for String { } impl From<&CharGrid> for Vec { - /// Converts a [CharGrid] into a [`Vec`]. + /// Converts a [`CharGrid`] into a [`Vec`]. /// /// Rows are not separated. /// diff --git a/src/containers/cp437_grid.rs b/src/containers/cp437_grid.rs index 79a0280..b74eba7 100644 --- a/src/containers/cp437_grid.rs +++ b/src/containers/cp437_grid.rs @@ -18,7 +18,7 @@ pub struct InvalidCharError { } impl Cp437Grid { - /// Load an ASCII-only [&str] into a [Cp437Grid] of specified width. + /// Load an ASCII-only [&str] into a [`Cp437Grid`] of specified width. /// /// # Panics /// diff --git a/src/containers/value_grid.rs b/src/containers/value_grid.rs index 208d6ce..090870d 100644 --- a/src/containers/value_grid.rs +++ b/src/containers/value_grid.rs @@ -1,9 +1,9 @@ use std::fmt::Debug; use std::slice::{Iter, IterMut}; -use crate::*; +use crate::{DataRef, Grid}; -/// A type that can be stored in a [ValueGrid], e.g. [char], [u8]. +/// A type that can be stored in a [`ValueGrid`], e.g. [char], [u8]. pub trait Value: Sized + Default + Copy + Clone + Debug {} impl Value for T {} @@ -12,7 +12,7 @@ impl Value for T {} /// The memory layout is the one the display expects in [Command]s. /// /// This structure can be used with any type that implements the [Value] trait. -/// You can also use the concrete type aliases provided in this crate, e.g. [CharGrid] and [ByteGrid]. +/// You can also use the concrete type aliases provided in this crate, e.g. [`CharGrid`] and [`ByteGrid`]. #[derive(Debug, Clone, PartialEq, Eq)] pub struct ValueGrid { width: usize, @@ -42,14 +42,14 @@ pub enum SetValueSeriesError { } impl ValueGrid { - /// Creates a new [ValueGrid] with the specified dimensions. + /// Creates a new [`ValueGrid`] with the specified dimensions. /// /// # Arguments /// /// - width: size in x-direction /// - height: size in y-direction /// - /// returns: [ValueGrid] initialized to default value. + /// returns: [`ValueGrid`] initialized to default value. #[must_use] pub fn new(width: usize, height: usize) -> Self { Self { @@ -59,9 +59,9 @@ impl ValueGrid { } } - /// Loads a [ValueGrid] with the specified dimensions from the provided data. + /// Loads a [`ValueGrid`] with the specified dimensions from the provided data. /// - /// returns: [ValueGrid] that contains a copy of the provided data, + /// returns: [`ValueGrid`] that contains a copy of the provided data, /// or None if the dimensions do not match the data size. #[must_use] pub fn load(width: usize, height: usize, data: &[T]) -> Option { @@ -75,11 +75,11 @@ impl ValueGrid { }) } - /// Creates a [ValueGrid] with the specified width from the provided data, + /// Creates a [`ValueGrid`] with the specified width from the provided data, /// wrapping to as many rows as needed, /// without copying the vec. /// - /// returns: [ValueGrid] that contains the provided data, + /// returns: [`ValueGrid`] that contains the provided data, /// or None if the data size is not divisible by the width. /// /// # Examples @@ -96,9 +96,9 @@ impl ValueGrid { return None; } Some(Self { - data, width, height, + data, }) } @@ -110,13 +110,13 @@ impl ValueGrid { ) -> Self { debug_assert_eq!(data.len(), width * height); Self { - data, width, height, + data, } } - /// Iterate over all cells in [ValueGrid]. + /// Iterate over all cells in [`ValueGrid`]. /// /// Order is equivalent to the following loop: /// ``` @@ -132,7 +132,7 @@ impl ValueGrid { self.data.iter() } - /// Iterate over all rows in [ValueGrid] top to bottom. + /// Iterate over all rows in [`ValueGrid`] top to bottom. pub fn iter_rows(&self) -> IterGridRows { IterGridRows { grid: self, row: 0 } } @@ -177,9 +177,9 @@ impl ValueGrid { } } - /// Convert between ValueGrid types. + /// Convert between `ValueGrid` types. /// - /// See also [Iterator::map]. + /// See also [`Iterator::map`]. /// /// # Examples /// @@ -215,16 +215,18 @@ impl ValueGrid { /// Copies a row from the grid. /// /// Returns [None] if y is out of bounds. + #[must_use] pub fn get_row(&self, y: usize) -> Option> { self.data .chunks_exact(self.width()) .nth(y) - .map(|row| row.to_vec()) + .map(<[T]>::to_vec) } /// Copies a column from the grid. /// /// Returns [None] if x is out of bounds. + #[must_use] pub fn get_col(&self, x: usize) -> Option> { self.data .chunks_exact(self.width()) @@ -480,7 +482,7 @@ mod tests { data_ref.copy_from_slice(&[1, 2, 3, 4]); assert_eq!(vec.data, [1, 2, 3, 4]); - assert_eq!(vec.get(1, 0), 2) + assert_eq!(vec.get(1, 0), 2); } #[test] diff --git a/src/cp437.rs b/src/cp437.rs index 7b5ad76..b374b1e 100644 --- a/src/cp437.rs +++ b/src/cp437.rs @@ -126,7 +126,7 @@ mod tests_feature_cp437 { let cp437 = str_to_cp437(utf8); let actual = cp437_to_str(&cp437); - assert_eq!(utf8, actual) + assert_eq!(utf8, actual); } #[test] diff --git a/src/packet.rs b/src/packet.rs index 2c0adce..452fd81 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -203,6 +203,6 @@ mod tests { #[test] fn too_small() { let data = vec![0u8; 4]; - assert_eq!(Packet::try_from(data.as_slice()), Err(())) + assert_eq!(Packet::try_from(data.as_slice()), Err(())); } }