Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Aug 7, 2024
1 parent 32a082b commit 836d534
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ within scope.

This crate offers the following traits:

### HetPixel
### `HetPixel`

The most foundational pixel trait implemented by every pixel type.

Expand Down Expand Up @@ -138,7 +138,7 @@ let rgba = rgba.map_same(|c| c * 2);
assert_eq!(rgba, Rgba::<u16> {r: 0, g: 0, b: 510, a: 0});
```

### GainAlpha
### `GainAlpha`

A way to add alpha to a pixel type in various ways.

Expand All @@ -152,7 +152,7 @@ assert_eq!(Rgb {r: 0, g: 0, b: 0}.with_alpha(255), expected);
assert_eq!(Rgba {r: 0, g: 0, b: 0, a: 0}.with_alpha(255), expected);
```

### HasAlpha
### `HasAlpha`

A trait only implemented on pixels that have an alpha
component.
Expand Down
2 changes: 1 addition & 1 deletion src/core_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ fn test_16_fmt() {
extern crate std;

let a = Argb::<u16>::new_argb(1, 0x1234, 3, 65535);
assert_eq!("argb(#000112340003FFFF)", &std::format!("{:X}", a));
assert_eq!("argb(#000112340003FFFF)", &std::format!("{a:X}"));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/formats/gray_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<T, A> Deref for GrayAlpha_v08<T, A> {

/// A trick that allows using `.v` and `.a` on the old `GrayAlpha` type.
fn deref(&self) -> &GrayA<T, A> {
unsafe { &*(self as *const Self as *const GrayA<T, A>) }
unsafe { &*(self as *const Self).cast::<GrayA<T, A>>() }
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/legacy/alt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::legacy::internal::pixel::*;
use crate::legacy::internal::pixel::{ColorComponentMap, ComponentSlice};
use core::slice;

pub use crate::formats::gray::Gray_v08 as Gray;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<T, A> GrayAlpha<T, A> {
/// Provide a mutable view of only `Gray` component (leaving out alpha).
#[inline(always)]
pub fn gray_mut(&mut self) -> &mut Gray<T> {
unsafe { &mut *(self as *mut _ as *mut _) }
unsafe { &mut *(self as *mut Self).cast() }
}
}

Expand All @@ -97,7 +97,7 @@ impl<T: Copy, A: Clone> GrayAlpha<T, A> {

/// Create a new `GrayAlpha` with the new alpha value, but same gray value
#[inline(always)]
pub fn with_alpha(&self, a: A) -> Self {
pub const fn with_alpha(&self, a: A) -> Self {
Self(self.0, a)
}

Expand Down Expand Up @@ -136,14 +136,14 @@ impl<T> ComponentSlice<T> for GrayAlpha<T> {
#[inline(always)]
fn as_slice(&self) -> &[T] {
unsafe {
slice::from_raw_parts(self as *const Self as *const T, 2)
slice::from_raw_parts((self as *const Self).cast::<T>(), 2)
}
}

#[inline(always)]
fn as_mut_slice(&mut self) -> &mut [T] {
unsafe {
slice::from_raw_parts_mut(self as *mut Self as *mut T, 2)
slice::from_raw_parts_mut((self as *mut Self).cast::<T>(), 2)
}
}
}
Expand Down Expand Up @@ -196,15 +196,15 @@ impl<T> ComponentSlice<T> for [Gray<T>] {
impl<T: Copy> From<Gray<T>> for GrayAlpha<T, u8> {
#[inline(always)]
fn from(other: Gray<T>) -> Self {
GrayAlpha(other.0, 0xFF)
Self(other.0, 0xFF)
}
}

/// Assumes 65535 is opaque
impl<T: Copy> From<Gray<T>> for GrayAlpha<T, u16> {
#[inline(always)]
fn from(other: Gray<T>) -> Self {
GrayAlpha(other.0, 0xFFFF)
Self(other.0, 0xFFFF)
}
}

Expand All @@ -226,7 +226,7 @@ fn gray() {

let g: GRAY8 = 200.into();
let g = g.map(|c| c / 2);
assert_eq!(110, g.v + 10);
assert_eq!(110, g.0 + 10);
assert_eq!(110, 10 + Gray(100).as_ref());

let ga: GRAYA8 = GrayAlpha(1, 2);
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/internal/rgb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::pixel::*;
use crate::alt::*;
use crate::*;
use super::pixel::{ColorComponentMap, ComponentBytes, ComponentSlice};

impl<T> BGR<T> {
/// Convenience function for creating a new pixel
Expand Down
20 changes: 10 additions & 10 deletions src/legacy/internal/rgba.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::pixel::*;
use crate::alt::*;
use crate::*;
use super::pixel::{ColorComponentMap, ComponentBytes, ComponentSlice};

impl<T, A> Rgba<T, A> {
#[inline(always)]
Expand Down Expand Up @@ -40,7 +40,7 @@ impl<T> Argb<T> {
/// The order of arguments is R,G,B,A
#[deprecated(note = "This function has a misleading order of arguments. Use ARGB{} literal instead")]
pub const fn new(r: T, g: T, b: T, a: T) -> Self {
Self { r, g, b, a }
Self { a, r, g, b }
}
}

Expand All @@ -50,7 +50,7 @@ impl<T, A> Argb<T, A> {
/// The order of arguments is R,G,B,A
#[deprecated(note = "This function has a misleading order of arguments. Use ARGB{} literal instead")]
pub const fn new_alpha(r: T, g: T, b: T, a: A) -> Self {
Self { r, g, b, a }
Self { a, r, g, b }
}
}

Expand All @@ -60,7 +60,7 @@ impl<T> Abgr<T> {
/// The order of arguments is R,G,B,A
#[deprecated(note = "This function has a misleading order of arguments. Use ABGR{} literal instead")]
pub const fn new(r: T, g: T, b: T, a: T) -> Self {
Self { r, g, b, a }
Self { a, b, g, r }
}
}

Expand All @@ -70,7 +70,7 @@ impl<T, A> Abgr<T, A> {
/// The order of arguments is R,G,B,A
#[deprecated(note = "This function has a misleading order of arguments. Use ABGR{} literal instead")]
pub const fn new_alpha(r: T, g: T, b: T, a: A) -> Self {
Self { r, g, b, a }
Self { a, b, g, r }
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ macro_rules! impl_rgba {

/// Create a new RGBA with the new alpha value, but same RGB values
#[inline(always)]
pub fn with_alpha(&self, a: A) -> Self {
pub const fn with_alpha(&self, a: A) -> Self {
Self { r: self.r, g: self.g, b: self.b, a }
}

Expand Down Expand Up @@ -235,7 +235,7 @@ impl<T, A> Rgba<T, A> {
/// Useful to change color without changing opacity.
#[inline(always)]
pub fn rgb_mut(&mut self) -> &mut Rgb<T> {
unsafe { &mut *(self as *mut _ as *mut Rgb<T>) }
unsafe { &mut *(self as *mut Self).cast::<Rgb<T>>() }
}
}

Expand All @@ -245,14 +245,14 @@ impl<T, A> BGRA<T, A> {
#[inline(always)]
#[deprecated(note = "This function will change. Use bgr_mut()")]
pub fn rgb_mut(&mut self) -> &mut Bgr<T> {
unsafe { &mut *(self as *mut _ as *mut Bgr<T>) }
unsafe { &mut *(self as *mut Self).cast::<Bgr<T>>() }
}

/// Provide a mutable view of only RGB components (leaving out alpha).
/// Useful to change color without changing opacity.
#[inline(always)]
pub fn bgr_mut(&mut self) -> &mut Bgr<T> {
unsafe { &mut *(self as *mut _ as *mut Bgr<T>) }
unsafe { &mut *(self as *mut Self).cast::<Bgr<T>>() }
}
}

Expand Down Expand Up @@ -362,7 +362,7 @@ fn rgba_test() {

#[cfg(feature = "as-bytes")]
{
let v = vec![RGBA::new(1u8,2,3,4), RGBA::new(5,6,7,8)];
let v = [RGBA::new(1u8,2,3,4), RGBA::new(5,6,7,8)];
assert_eq!(&[1,2,3,4,5,6,7,8], v.as_bytes());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn bytes() {
assert_eq!(&[1,2,3,4], rgba_bytes);
assert_eq!(&[rgba], rgba_bytes.as_rgba());
rgba_bytes[3] = 99;
assert_eq!(RGBA8::new(1,2,3,99), rgba_arr.as_bytes().into_iter().cloned().collect());
assert_eq!(RGBA8::new(1,2,3,99), rgba_arr.as_bytes().iter().copied().collect());
}

let rgb = RGB16::new(1,2,3);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub mod prelude {
pub use crate::Pixel;
}

/// TryFrom errors
/// `TryFrom` errors
pub mod error {
pub use crate::pixel_traits::het_pixel::TryFromColorsAlphaError;
pub use crate::pixel_traits::pixel::TryFromComponentsError;
Expand Down

0 comments on commit 836d534

Please sign in to comment.