remove redundant bounds (Deref is supertrait of DerefMut)

This commit is contained in:
bendn 2023-09-26 12:32:12 +07:00
parent eed6423cba
commit 7c800b700e
No known key found for this signature in database
GPG key ID: 0D9D3A2A3B2A93D6
6 changed files with 20 additions and 42 deletions

View file

@ -1,5 +1,5 @@
//! Manages the affine image transformations.
use std::ops::{Deref, DerefMut};
use std::ops::DerefMut;
use crate::{cloner::ImageCloner, Image};
@ -45,7 +45,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
}
}
impl<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>> Image<T, CHANNELS> {
impl<const CHANNELS: usize, T: DerefMut<Target = [u8]>> Image<T, CHANNELS> {
/// Flip an image vertically.
pub fn flip_v(&mut self) {
for y in 0..self.height() / 2 {
@ -131,7 +131,7 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
}
}
impl<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>> Image<T, CHANNELS> {
impl<const CHANNELS: usize, T: DerefMut<Target = [u8]>> Image<T, CHANNELS> {
/// Rotate an image 180 degrees clockwise.
pub fn rot_180(&mut self) {
self.flatten_mut().reverse();
@ -166,7 +166,7 @@ impl<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>> I
/// # Safety
///
/// UB if supplied image rectangular
unsafe fn transpose<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Target = [u8]>>(
unsafe fn transpose<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
img: &mut Image<T, CHANNELS>,
) {
debug_assert_eq!(img.width(), img.height());
@ -184,10 +184,7 @@ unsafe fn transpose<const CHANNELS: usize, T: Deref<Target = [u8]> + DerefMut<Ta
/// # Safety
///
/// UB if image not square
unsafe fn transpose_non_power_of_two<
const CHANNELS: usize,
T: Deref<Target = [u8]> + DerefMut<Target = [u8]>,
>(
unsafe fn transpose_non_power_of_two<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
img: &mut Image<T, CHANNELS>,
) {
debug_assert_eq!(img.width(), img.height());
@ -208,10 +205,7 @@ const TILE: usize = 4;
/// # Safety
///
/// be careful
unsafe fn transpose_tile<
const CHANNELS: usize,
T: Deref<Target = [u8]> + DerefMut<Target = [u8]>,
>(
unsafe fn transpose_tile<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
img: &mut Image<T, CHANNELS>,
row: usize,
col: usize,
@ -247,10 +241,7 @@ unsafe fn transpose_tile<
/// # Safety
///
/// be careful
unsafe fn transpose_diag<
const CHANNELS: usize,
T: Deref<Target = [u8]> + DerefMut<Target = [u8]>,
>(
unsafe fn transpose_diag<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(
img: &mut Image<T, CHANNELS>,
pos: usize,
size: usize,

View file

@ -1,9 +1,9 @@
//! `Box<cat>`
use std::ops::{Deref, DerefMut, Range};
use std::ops::{DerefMut, Range};
use crate::Image;
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
/// Draw a bordered box
/// ```
/// # use fimg::Image;

View file

@ -1,10 +1,7 @@
//! adds a `line` function to Image
#![allow(clippy::missing_docs_in_private_items)]
use crate::Image;
use std::{
iter::Iterator,
ops::{Deref, DerefMut},
};
use std::{iter::Iterator, ops::DerefMut};
/// taken from [bresenham-rs](https://github.com/mbr/bresenham-rs)
pub struct Bresenham {
@ -130,7 +127,7 @@ impl Iterator for Bresenham {
}
}
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
/// Draw a line from point a to point b.
///
/// Points not in bounds will not be included.

View file

@ -1,12 +1,12 @@
//! draw polygons
use std::{
cmp::{max, min},
ops::{Deref, DerefMut},
ops::DerefMut,
};
use crate::Image;
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
/// Draws a filled polygon from a slice of points. Please close your poly. (first == last)
///
/// Borrowed from [imageproc](https://docs.rs/imageproc/latest/src/imageproc/drawing/polygon.rs.html#31), modified for less allocations.

View file

@ -1,9 +1,9 @@
//! trongle drawing
use std::ops::{Deref, DerefMut};
use std::ops::DerefMut;
use crate::Image;
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
impl<T: DerefMut<Target = [u8]>, const CHANNELS: usize> Image<T, CHANNELS> {
/// Draw a (filled) triangle
/// ```
/// # use fimg::*;

View file

@ -100,9 +100,7 @@ unsafe fn blit(rgb: &mut [u8], rgba: &[u8]) {
}
}
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
Overlay<Image<U, 4>> for Image<T, 4>
{
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> Overlay<Image<U, 4>> for Image<T, 4> {
#[inline]
unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self {
debug_assert!(self.width() == with.width());
@ -129,9 +127,7 @@ impl ClonerOverlay<4, 4> for ImageCloner<'_, 4> {
}
}
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
OverlayAt<Image<U, 4>> for Image<T, 3>
{
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> OverlayAt<Image<U, 4>> for Image<T, 3> {
#[inline]
unsafe fn overlay_at(&mut self, with: &Image<U, 4>, x: u32, y: u32) -> &mut Self {
// SAFETY: caller upholds this
@ -167,9 +163,7 @@ impl ClonerOverlayAt<4, 3> for ImageCloner<'_, 3> {
}
}
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
OverlayAt<Image<U, 3>> for Image<T, 3>
{
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> OverlayAt<Image<U, 3>> for Image<T, 3> {
/// Overlay a RGB image(with) => self at coordinates x, y.
/// As this is a `RGBxRGB` operation, blending is unnecessary,
/// and this is simply a copy.
@ -208,9 +202,7 @@ impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
}
}
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
Overlay<Image<U, 4>> for Image<T, 3>
{
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> Overlay<Image<U, 4>> for Image<T, 3> {
#[inline]
unsafe fn overlay(&mut self, with: &Image<U, 4>) -> &mut Self {
debug_assert!(self.width() == with.width());
@ -244,9 +236,7 @@ impl ClonerOverlay<4, 3> for ImageCloner<'_, 3> {
}
}
impl<T: Deref<Target = [u8]> + DerefMut<Target = [u8]>, U: Deref<Target = [u8]>>
OverlayAt<Image<U, 4>> for Image<T, 4>
{
impl<T: DerefMut<Target = [u8]>, U: Deref<Target = [u8]>> OverlayAt<Image<U, 4>> for Image<T, 4> {
#[inline]
/// Overlay with => self at coordinates x, y, without blending
///