it only worked for methods explicitly mentioned
This commit is contained in:
parent
23e2dc4f1a
commit
90054f1ff0
10 changed files with 23 additions and 47 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
|
|||
|
|
@ -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,10 @@ 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 +218,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].
|
||||
///
|
||||
|
|
@ -245,7 +242,7 @@ impl GridMut<bool> for Bitmap {
|
|||
///
|
||||
/// 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
|
||||
|
|
@ -261,7 +258,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Brightness, ByteGrid, ValueGrid};
|
||||
use crate::{Brightness, ByteGrid, Grid, ValueGrid};
|
||||
|
||||
/// A grid containing brightness values.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -154,6 +154,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
|
||||
|
|
|
|||
|
|
@ -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,10 @@ 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 +282,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.
|
||||
///
|
||||
|
|
@ -307,7 +304,7 @@ impl<T: Value> GridMut<T> for ValueGrid<T> {
|
|||
///
|
||||
/// 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
|
||||
|
|
@ -317,7 +314,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,13 +113,12 @@ 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 {
|
||||
|
|
@ -129,13 +128,13 @@ 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 +144,11 @@ 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
|
||||
|
|
@ -165,7 +158,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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue