1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Enable the clippy::std_instead_of_core lint (#8394)

Prefer `core::` over `std::` where either work

* Part of https://github.com/emilk/egui/issues/5735
This commit is contained in:
Emil Ernerfeldt
2026-08-06 04:19:13 -07:00
committed by GitHub
parent 2a5f3d99b5
commit 6aea7eff94
176 changed files with 633 additions and 615 deletions

View File

@@ -30,15 +30,15 @@ use crate::{Rgba, fast_round, linear_f32_from_linear_u8};
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct Color32(pub(crate) [u8; 4]);
impl std::fmt::Debug for Color32 {
impl core::fmt::Debug for Color32 {
/// Prints the contents with premultiplied alpha!
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let [r, g, b, a] = self.0;
write!(f, "#{r:02X}_{g:02X}_{b:02X}_{a:02X}")
}
}
impl std::ops::Index<usize> for Color32 {
impl core::ops::Index<usize> for Color32 {
type Output = u8;
#[inline]
@@ -47,7 +47,7 @@ impl std::ops::Index<usize> for Color32 {
}
}
impl std::ops::IndexMut<usize> for Color32 {
impl core::ops::IndexMut<usize> for Color32 {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut u8 {
&mut self.0[index]
@@ -378,7 +378,7 @@ impl Color32 {
}
}
impl std::ops::Mul for Color32 {
impl core::ops::Mul for Color32 {
type Output = Self;
/// Fast gamma-space multiplication.
@@ -393,7 +393,7 @@ impl std::ops::Mul for Color32 {
}
}
impl std::ops::Add for Color32 {
impl core::ops::Add for Color32 {
type Output = Self;
#[inline]
@@ -489,7 +489,7 @@ mod test {
} else {
// There will be small rounding errors whenever the alpha is not 0 or 255,
// because we multiply and then unmultiply the alpha.
for (&a, &b) in std::iter::zip(&in_rgba, &out_rgba) {
for (&a, &b) in core::iter::zip(&in_rgba, &out_rgba) {
assert!(a.abs_diff(b) <= 3, "{in_rgba:?} != {out_rgba:?}");
}
}

View File

@@ -3,7 +3,7 @@
//! Supports the 3, 4, 6, and 8-digit formats, according to the specification in
//! <https://drafts.csswg.org/css-color-4/#hex-color>
use std::{fmt::Display, str::FromStr};
use core::{fmt::Display, str::FromStr};
use crate::Color32;
@@ -31,7 +31,7 @@ pub enum HexColor {
pub enum ParseHexColorError {
MissingHash,
InvalidLength,
InvalidInt(std::num::ParseIntError),
InvalidInt(core::num::ParseIntError),
}
impl FromStr for HexColor {
@@ -45,7 +45,7 @@ impl FromStr for HexColor {
}
impl Display for HexColor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Hex3(color) => {
let [r, g, b, _] = color.to_srgba_unmultiplied().map(|u| u >> 4);

View File

@@ -9,7 +9,7 @@ use crate::Color32;
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct Rgba(pub(crate) [f32; 4]);
impl std::ops::Index<usize> for Rgba {
impl core::ops::Index<usize> for Rgba {
type Output = f32;
#[inline]
@@ -18,7 +18,7 @@ impl std::ops::Index<usize> for Rgba {
}
}
impl std::ops::IndexMut<usize> for Rgba {
impl core::ops::IndexMut<usize> for Rgba {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut f32 {
&mut self.0[index]
@@ -27,20 +27,20 @@ impl std::ops::IndexMut<usize> for Rgba {
/// Deterministically hash an `f32`, treating all NANs as equal, and ignoring the sign of zero.
#[inline]
pub(crate) fn f32_hash<H: std::hash::Hasher>(state: &mut H, f: f32) {
pub(crate) fn f32_hash<H: core::hash::Hasher>(state: &mut H, f: f32) {
if f == 0.0 {
state.write_u8(0);
} else if f.is_nan() {
state.write_u8(1);
} else {
use std::hash::Hash as _;
use core::hash::Hash as _;
f.to_bits().hash(state);
}
}
impl std::hash::Hash for Rgba {
impl core::hash::Hash for Rgba {
#[inline]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
crate::f32_hash(state, self.0[0]);
crate::f32_hash(state, self.0[1]);
crate::f32_hash(state, self.0[2]);
@@ -219,7 +219,7 @@ impl Rgba {
}
}
impl std::ops::Add for Rgba {
impl core::ops::Add for Rgba {
type Output = Self;
#[inline]
@@ -233,7 +233,7 @@ impl std::ops::Add for Rgba {
}
}
impl std::ops::Mul for Rgba {
impl core::ops::Mul for Rgba {
type Output = Self;
#[inline]
@@ -247,7 +247,7 @@ impl std::ops::Mul for Rgba {
}
}
impl std::ops::Mul<f32> for Rgba {
impl core::ops::Mul<f32> for Rgba {
type Output = Self;
#[inline]
@@ -261,7 +261,7 @@ impl std::ops::Mul<f32> for Rgba {
}
}
impl std::ops::Mul<Rgba> for f32 {
impl core::ops::Mul<Rgba> for f32 {
type Output = Rgba;
#[inline]
@@ -336,7 +336,7 @@ mod test {
} else {
// There will be small rounding errors whenever the alpha is not 0 or 255,
// because we multiply and then unmultiply the alpha.
for (&a, &b) in std::iter::zip(&in_rgba, &out_rgba) {
for (&a, &b) in core::iter::zip(&in_rgba, &out_rgba) {
assert!(a.abs_diff(b) <= 3, "{in_rgba:?} != {out_rgba:?}");
}
}