remove inherent
Some checks failed
Rust / build (pull_request) Failing after 1m4s

it only worked for methods explicitly mentioned
This commit is contained in:
Vinzenz Schroeter 2025-07-09 22:35:16 +02:00
parent 77c4c38cfb
commit a129a48b36
11 changed files with 50 additions and 59 deletions

14
Cargo.lock generated
View file

@ -201,17 +201,6 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "inherent"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c38228f24186d9cc68c729accb4d413be9eaed6ad07ff79e0270d9e56f3de13"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
@ -347,13 +336,12 @@ dependencies = [
[[package]]
name = "servicepoint"
version = "0.15.2"
version = "0.16.0"
dependencies = [
"bitvec",
"bzip2",
"clap",
"flate2",
"inherent",
"log",
"once_cell",
"rand",

View file

@ -1,6 +1,6 @@
[package]
name = "servicepoint"
version = "0.15.2"
version = "0.16.0"
publish = true
edition = "2021"
license = "GPL-3.0-or-later"
@ -24,7 +24,6 @@ rust-lzma = { version = "0.6", optional = true }
rand = { version = "0.9", optional = true }
once_cell = { version = "1.20", optional = true }
thiserror = "2.0"
inherent = "1.0"
[features]
default = ["compression_lzma", "cp437"]

View file

@ -3,7 +3,7 @@
use clap::Parser;
use servicepoint::{
Bitmap, BitmapCommand, Brightness, BrightnessGrid, BrightnessGridCommand,
DataRef, UdpSocketExt, TILE_HEIGHT, TILE_WIDTH,
DataRef, GridMut, UdpSocketExt, TILE_HEIGHT, TILE_WIDTH,
};
use std::net::UdpSocket;

View file

@ -5,7 +5,7 @@ use clap::Parser;
use rand::Rng;
use servicepoint::{
Bitmap, BitmapCommand, Brightness, BrightnessGrid, BrightnessGridCommand,
GlobalBrightnessCommand, Grid, GridMut, Origin, UdpSocketExt, TILE_HEIGHT,
GlobalBrightnessCommand, GridMut, Origin, UdpSocketExt, TILE_HEIGHT,
TILE_WIDTH,
};
use std::{net::UdpSocket, time::Duration};

View file

@ -2,7 +2,7 @@ use crate::{
command_code::{CommandCode, InvalidCommandCodeError},
commands::errors::{TryFromPacketError, TryIntoPacketError},
compression::{compress, decompress, CompressionError},
Bitmap, CompressionCode, DataRef, Header, Origin, Packet, Pixels,
Bitmap, CompressionCode, DataRef, Grid, Header, Origin, Packet, Pixels,
TypedCommand, TILE_SIZE,
};
@ -183,6 +183,7 @@ mod tests {
use super::*;
use crate::{
command_code::CommandCode, commands::tests::TestImplementsCommand,
GridMut,
};
impl TestImplementsCommand for BitmapCommand {}
@ -325,4 +326,17 @@ mod tests {
);
}
}
#[test]
fn invalid_y() {
let command = BitmapCommand {
bitmap: Bitmap::new(8, 3).unwrap(),
origin: Origin::new(4, u16::MAX as usize + 1),
compression: CompressionCode::Uncompressed,
};
assert!(matches!(
Packet::try_from(command),
Err(TryIntoPacketError::ConversionError(_)),
))
}
}

View file

@ -414,4 +414,18 @@ mod tests {
}
);
}
#[test]
fn invalid_offset() {
let command = BitVecCommand {
bitvec: DisplayBitVec::repeat(false, 16),
offset: u16::MAX as usize + 1,
operation: BinaryOperation::Or,
compression: CompressionCode::Uncompressed,
};
assert!(matches!(
Packet::try_from(command),
Err(TryIntoPacketError::ConversionError(_)),
))
}
}

View file

@ -3,7 +3,6 @@ use crate::{
GridMut, Payload, ValueGrid, Window, WindowMut, PIXEL_HEIGHT, PIXEL_WIDTH,
};
use ::bitvec::{order::Msb0, prelude::BitSlice, slice::IterMut};
use inherent::inherent;
use std::ops::RangeBounds;
/// A fixed-size 2D grid of booleans.
@ -206,11 +205,9 @@ impl Bitmap {
}
}
#[inherent]
impl Grid<bool> for Bitmap {
#[must_use]
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn get_optional(&self, x: usize, y: usize) -> Option<bool> {
fn get_optional(&self, x: usize, y: usize) -> Option<bool> {
let index = x + y * self.width;
if self.is_in_bounds(x, y) {
Some(self.bit_vec[index])
@ -220,17 +217,16 @@ impl Grid<bool> for Bitmap {
}
#[must_use]
pub fn width(&self) -> usize {
fn width(&self) -> usize {
self.width
}
#[must_use]
pub fn height(&self) -> usize {
fn height(&self) -> usize {
self.height
}
}
#[inherent]
impl GridMut<bool> for Bitmap {
/// Sets the value of the specified position in the [Bitmap].
///
@ -244,8 +240,7 @@ impl GridMut<bool> for Bitmap {
/// # Panics
///
/// When accessing `x` or `y` out of bounds.
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn set_optional(&mut self, x: usize, y: usize, value: bool) -> bool {
fn set_optional(&mut self, x: usize, y: usize, value: bool) -> bool {
if self.is_in_bounds(x, y) {
self.bit_vec.set(x + y * self.width, value);
true
@ -260,8 +255,7 @@ impl GridMut<bool> for Bitmap {
///
/// - `this`: instance to write to
/// - `value`: the value to set all pixels to
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn fill(&mut self, value: bool) {
fn fill(&mut self, value: bool) {
self.bit_vec.fill(value);
}
}

View file

@ -1,4 +1,4 @@
use crate::{Brightness, ByteGrid, ValueGrid};
use crate::{Brightness, ByteGrid, Grid, ValueGrid};
/// A grid containing brightness values.
///

View file

@ -146,6 +146,7 @@ impl From<CharGrid> for Vec<u8> {
#[cfg(test)]
mod test {
use super::*;
use crate::Grid;
#[test]
fn str_to_char_grid() {
// conversion with .to_string() covers one more line

View file

@ -2,7 +2,6 @@ use crate::{
containers::absolute_bounds_to_abs_range, DataRef, Grid, GridMut, Window,
WindowMut,
};
use inherent::inherent;
use std::{
fmt::Debug,
ops::RangeBounds,
@ -271,11 +270,9 @@ pub enum TryLoadValueGridError {
InvalidDimensions,
}
#[inherent]
impl<T: Value> Grid<T> for ValueGrid<T> {
#[must_use]
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn get_optional(&self, x: usize, y: usize) -> Option<T> {
fn get_optional(&self, x: usize, y: usize) -> Option<T> {
if self.is_in_bounds(x, y) {
Some(self.data[x + y * self.width])
} else {
@ -284,17 +281,16 @@ impl<T: Value> Grid<T> for ValueGrid<T> {
}
#[must_use]
pub fn width(&self) -> usize {
fn width(&self) -> usize {
self.width
}
#[must_use]
pub fn height(&self) -> usize {
fn height(&self) -> usize {
self.height
}
}
#[inherent]
impl<T: Value> GridMut<T> for ValueGrid<T> {
/// Sets the value of the cell at the specified position in the grid.
///
@ -306,8 +302,7 @@ impl<T: Value> GridMut<T> for ValueGrid<T> {
/// # Panics
///
/// When accessing `x` or `y` out of bounds.
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn set_optional(&mut self, x: usize, y: usize, value: T) -> bool {
fn set_optional(&mut self, x: usize, y: usize, value: T) -> bool {
if self.is_in_bounds(x, y) {
self.data[x + y * self.width] = value;
true
@ -316,8 +311,7 @@ impl<T: Value> GridMut<T> for ValueGrid<T> {
}
}
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn fill(&mut self, value: T) {
fn fill(&mut self, value: T) {
self.data.fill(value);
}
}

View file

@ -26,7 +26,6 @@ macro_rules! define_window {
{
/// Create a new window into `grid`.
#[must_use]
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn new(
grid: $grid,
xs: impl RangeBounds<usize>,
@ -113,13 +112,11 @@ macro_rules! define_window {
}
}
#[inherent::inherent]
impl<TElement: Copy, TGrid: Grid<TElement>> Grid<TElement>
for $name<'_, TElement, TGrid>
{
#[must_use]
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn get_optional(&self, x: usize, y: usize) -> Option<TElement> {
fn get_optional(&self, x: usize, y: usize) -> Option<TElement> {
if self.is_in_bounds(x, y) {
Some(self.grid.get(self.xs.start + x, self.ys.start + y))
} else {
@ -128,14 +125,12 @@ macro_rules! define_window {
}
#[must_use]
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn width(&self) -> usize {
fn width(&self) -> usize {
self.xs.len()
}
#[must_use]
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn height(&self) -> usize {
fn height(&self) -> usize {
self.ys.len()
}
}
@ -145,17 +140,10 @@ macro_rules! define_window {
define_window!(Window, &'t TGrid);
define_window!(WindowMut, &'t mut TGrid);
#[inherent::inherent]
impl<TElement: Copy, TGrid: GridMut<TElement>> GridMut<TElement>
for WindowMut<'_, TElement, TGrid>
{
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn set_optional(
&mut self,
x: usize,
y: usize,
value: TElement,
) -> bool {
fn set_optional(&mut self, x: usize, y: usize, value: TElement) -> bool {
if self.is_in_bounds(x, y) {
self.grid.set(self.xs.start + x, self.ys.start + y, value);
true
@ -164,8 +152,7 @@ impl<TElement: Copy, TGrid: GridMut<TElement>> GridMut<TElement>
}
}
#[allow(unused, reason = "False positive because of #[inherent]")]
pub fn fill(&mut self, value: TElement) {
fn fill(&mut self, value: TElement) {
for y in self.ys.clone() {
for x in self.xs.clone() {
self.grid.set(x, y, value);