mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -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:
@@ -274,7 +274,7 @@ impl Align2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Index<usize> for Align2 {
|
||||
impl core::ops::Index<usize> for Align2 {
|
||||
type Output = Align;
|
||||
|
||||
#[inline(always)]
|
||||
@@ -283,7 +283,7 @@ impl std::ops::Index<usize> for Align2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<usize> for Align2 {
|
||||
impl core::ops::IndexMut<usize> for Align2 {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, index: usize) -> &mut Align {
|
||||
&mut self.0[index]
|
||||
@@ -299,8 +299,8 @@ pub fn center_size_in_rect(size: Vec2, frame: Rect) -> Rect {
|
||||
Align2::CENTER_CENTER.align_size_within_rect(size, frame)
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Align2 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for Align2 {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "Align2({:?}, {:?})", self.x(), self.y())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! All functions take a value in `[0, 1]` and return a value in `[0, 1]`.
|
||||
//!
|
||||
//! Derived from <https://github.com/warrenm/AHEasing/blob/master/AHEasing/easing.c>.
|
||||
use std::f32::consts::PI;
|
||||
use core::f32::consts::PI;
|
||||
|
||||
use crate::fast_midpoint;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ where
|
||||
/// history.add(now(), 44.0_f32);
|
||||
/// assert_eq!(history.average(), Some(42.0));
|
||||
/// ```
|
||||
pub fn new(length_range: std::ops::Range<usize>, max_age: f32) -> Self {
|
||||
pub fn new(length_range: core::ops::Range<usize>, max_age: f32) -> Self {
|
||||
Self {
|
||||
min_len: length_range.start,
|
||||
max_len: length_range.end,
|
||||
@@ -175,8 +175,8 @@ where
|
||||
impl<T> History<T>
|
||||
where
|
||||
T: Copy,
|
||||
T: std::iter::Sum,
|
||||
T: std::ops::Div<f32, Output = T>,
|
||||
T: core::iter::Sum,
|
||||
T: core::ops::Div<f32, Output = T>,
|
||||
{
|
||||
#[inline]
|
||||
pub fn sum(&self) -> T {
|
||||
@@ -196,9 +196,9 @@ where
|
||||
impl<T> History<T>
|
||||
where
|
||||
T: Copy,
|
||||
T: std::iter::Sum,
|
||||
T: std::ops::Div<f32, Output = T>,
|
||||
T: std::ops::Mul<f32, Output = T>,
|
||||
T: core::iter::Sum,
|
||||
T: core::ops::Div<f32, Output = T>,
|
||||
T: core::ops::Mul<f32, Output = T>,
|
||||
{
|
||||
/// Average times rate.
|
||||
/// If you are keeping track of individual sizes of things (e.g. bytes),
|
||||
@@ -211,8 +211,8 @@ where
|
||||
impl<T, Vel> History<T>
|
||||
where
|
||||
T: Copy,
|
||||
T: std::ops::Sub<Output = Vel>,
|
||||
Vel: std::ops::Div<f32, Output = Vel>,
|
||||
T: core::ops::Sub<Output = Vel>,
|
||||
Vel: core::ops::Div<f32, Output = Vel>,
|
||||
{
|
||||
/// Calculate a smooth velocity (per second) over the entire time span.
|
||||
/// Calculated as the last value minus the first value over the elapsed time between them.
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#![expect(clippy::float_cmp)]
|
||||
|
||||
use std::ops::{Add, Div, Mul, RangeInclusive, Sub};
|
||||
use core::ops::{Add, Div, Mul, RangeInclusive, Sub};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -269,7 +269,7 @@ fn test_format() {
|
||||
assert_eq!(format_with_minimum_decimals(3.14, 2), "3.14");
|
||||
assert_eq!(format_with_minimum_decimals(3.14, 3), "3.140");
|
||||
assert_eq!(
|
||||
format_with_minimum_decimals(std::f64::consts::PI, 2),
|
||||
format_with_minimum_decimals(core::f64::consts::PI, 2),
|
||||
"3.14159"
|
||||
);
|
||||
}
|
||||
@@ -365,7 +365,7 @@ impl_num_ext!(Pos2);
|
||||
|
||||
/// Wrap angle to `[-PI, PI]` range.
|
||||
pub fn normalized_angle(mut angle: f32) -> f32 {
|
||||
use std::f32::consts::{PI, TAU};
|
||||
use core::f32::consts::{PI, TAU};
|
||||
angle %= TAU;
|
||||
if angle > PI {
|
||||
angle -= TAU;
|
||||
@@ -385,7 +385,7 @@ fn test_normalized_angle() {
|
||||
};
|
||||
}
|
||||
|
||||
use std::f32::consts::TAU;
|
||||
use core::f32::consts::TAU;
|
||||
almost_eq!(normalized_angle(-3.0 * TAU), 0.0);
|
||||
almost_eq!(normalized_angle(-2.3 * TAU), -0.3 * TAU);
|
||||
almost_eq!(normalized_angle(-TAU), 0.0);
|
||||
|
||||
@@ -92,9 +92,9 @@ impl_numeric_integer!(i64);
|
||||
impl_numeric_integer!(u64);
|
||||
impl_numeric_integer!(isize);
|
||||
impl_numeric_integer!(usize);
|
||||
impl_numeric_non_zero_unsigned!(std::num::NonZeroU8);
|
||||
impl_numeric_non_zero_unsigned!(std::num::NonZeroU16);
|
||||
impl_numeric_non_zero_unsigned!(std::num::NonZeroU32);
|
||||
impl_numeric_non_zero_unsigned!(std::num::NonZeroU64);
|
||||
impl_numeric_non_zero_unsigned!(std::num::NonZeroU128);
|
||||
impl_numeric_non_zero_unsigned!(std::num::NonZeroUsize);
|
||||
impl_numeric_non_zero_unsigned!(core::num::NonZeroU8);
|
||||
impl_numeric_non_zero_unsigned!(core::num::NonZeroU16);
|
||||
impl_numeric_non_zero_unsigned!(core::num::NonZeroU32);
|
||||
impl_numeric_non_zero_unsigned!(core::num::NonZeroU64);
|
||||
impl_numeric_non_zero_unsigned!(core::num::NonZeroU128);
|
||||
impl_numeric_non_zero_unsigned!(core::num::NonZeroUsize);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Total order on floating point types.
|
||||
//! Can be used for sorting, min/max computation, and other collection algorithms.
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use core::cmp::Ordering;
|
||||
use core::hash::{Hash, Hasher};
|
||||
|
||||
/// Wraps a floating-point value to add total order and hash.
|
||||
/// Possible types for `T` are `f32` and `f64`.
|
||||
@@ -21,9 +21,9 @@ impl<T: Float + Copy> OrderedFloat<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: std::fmt::Debug> std::fmt::Debug for OrderedFloat<T> {
|
||||
impl<T: core::fmt::Debug> core::fmt::Debug for OrderedFloat<T> {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{
|
||||
use core::{
|
||||
fmt,
|
||||
ops::{Add, AddAssign, MulAssign, Sub, SubAssign},
|
||||
};
|
||||
@@ -206,7 +206,7 @@ impl Pos2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Index<usize> for Pos2 {
|
||||
impl core::ops::Index<usize> for Pos2 {
|
||||
type Output = f32;
|
||||
|
||||
#[inline(always)]
|
||||
@@ -219,7 +219,7 @@ impl std::ops::Index<usize> for Pos2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<usize> for Pos2 {
|
||||
impl core::ops::IndexMut<usize> for Pos2 {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, index: usize) -> &mut f32 {
|
||||
match index {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::ops::{RangeFrom, RangeFull, RangeInclusive, RangeToInclusive};
|
||||
use core::ops::{RangeFrom, RangeFull, RangeInclusive, RangeToInclusive};
|
||||
|
||||
use crate::fast_midpoint;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::fmt;
|
||||
|
||||
use crate::{Div, Mul, NumExt as _, Pos2, Rangef, Rot2, Vec2, fast_midpoint, lerp, pos2, vec2};
|
||||
use std::ops::{BitOr, BitOrAssign};
|
||||
use core::ops::{BitOr, BitOrAssign};
|
||||
|
||||
/// A rectangular region of space.
|
||||
///
|
||||
@@ -727,7 +727,7 @@ impl Rect {
|
||||
let mut t1 = (self.max[i] - self.center()[i]) * inv_d;
|
||||
|
||||
if inv_d < 0.0 {
|
||||
std::mem::swap(&mut t0, &mut t1);
|
||||
core::mem::swap(&mut t0, &mut t1);
|
||||
}
|
||||
|
||||
tmin = tmin.max(t0);
|
||||
|
||||
@@ -65,7 +65,7 @@ impl RectTransform {
|
||||
}
|
||||
|
||||
/// Transforms the position.
|
||||
impl std::ops::Mul<Pos2> for RectTransform {
|
||||
impl core::ops::Mul<Pos2> for RectTransform {
|
||||
type Output = Pos2;
|
||||
|
||||
fn mul(self, pos: Pos2) -> Pos2 {
|
||||
@@ -74,7 +74,7 @@ impl std::ops::Mul<Pos2> for RectTransform {
|
||||
}
|
||||
|
||||
/// Transforms the position.
|
||||
impl std::ops::Mul<Pos2> for &RectTransform {
|
||||
impl core::ops::Mul<Pos2> for &RectTransform {
|
||||
type Output = Pos2;
|
||||
|
||||
fn mul(self, pos: Pos2) -> Pos2 {
|
||||
|
||||
@@ -92,8 +92,8 @@ impl Rot2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Rot2 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
impl core::fmt::Debug for Rot2 {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
if let Some(precision) = f.precision() {
|
||||
write!(
|
||||
f,
|
||||
@@ -113,7 +113,7 @@ impl std::fmt::Debug for Rot2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<Self> for Rot2 {
|
||||
impl core::ops::Mul<Self> for Rot2 {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
@@ -130,7 +130,7 @@ impl std::ops::Mul<Self> for Rot2 {
|
||||
}
|
||||
|
||||
/// Rotates (and maybe scales) the vector.
|
||||
impl std::ops::Mul<Vec2> for Rot2 {
|
||||
impl core::ops::Mul<Vec2> for Rot2 {
|
||||
type Output = Vec2;
|
||||
|
||||
#[inline]
|
||||
@@ -143,7 +143,7 @@ impl std::ops::Mul<Vec2> for Rot2 {
|
||||
}
|
||||
|
||||
/// Scales the rotor.
|
||||
impl std::ops::Mul<Rot2> for f32 {
|
||||
impl core::ops::Mul<Rot2> for f32 {
|
||||
type Output = Rot2;
|
||||
|
||||
#[inline]
|
||||
@@ -156,7 +156,7 @@ impl std::ops::Mul<Rot2> for f32 {
|
||||
}
|
||||
|
||||
/// Scales the rotor.
|
||||
impl std::ops::Mul<f32> for Rot2 {
|
||||
impl core::ops::Mul<f32> for Rot2 {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
@@ -169,7 +169,7 @@ impl std::ops::Mul<f32> for Rot2 {
|
||||
}
|
||||
|
||||
/// Scales the rotor.
|
||||
impl std::ops::Div<f32> for Rot2 {
|
||||
impl core::ops::Div<f32> for Rot2 {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
@@ -189,7 +189,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_rotation2() {
|
||||
{
|
||||
let angle = std::f32::consts::TAU / 6.0;
|
||||
let angle = core::f32::consts::TAU / 6.0;
|
||||
let rot = Rot2::from_angle(angle);
|
||||
assert!((rot.angle() - angle).abs() < 1e-5);
|
||||
assert!((rot * rot.inverse()).angle().abs() < 1e-5);
|
||||
@@ -197,14 +197,14 @@ mod test {
|
||||
}
|
||||
|
||||
{
|
||||
let angle = std::f32::consts::TAU / 4.0;
|
||||
let angle = core::f32::consts::TAU / 4.0;
|
||||
let rot = Rot2::from_angle(angle);
|
||||
assert!(((rot * vec2(1.0, 0.0)) - vec2(0.0, 1.0)).length() < 1e-5);
|
||||
}
|
||||
|
||||
{
|
||||
// Test rotation and scaling
|
||||
let angle = std::f32::consts::TAU / 4.0;
|
||||
let angle = core::f32::consts::TAU / 4.0;
|
||||
let rot = 3.0 * Rot2::from_angle(angle);
|
||||
let rotated = rot * vec2(1.0, 0.0);
|
||||
let expected = vec2(0.0, 3.0);
|
||||
|
||||
@@ -109,7 +109,7 @@ impl TSTransform {
|
||||
}
|
||||
|
||||
/// Transforms the position.
|
||||
impl std::ops::Mul<Pos2> for TSTransform {
|
||||
impl core::ops::Mul<Pos2> for TSTransform {
|
||||
type Output = Pos2;
|
||||
|
||||
#[inline]
|
||||
@@ -119,7 +119,7 @@ impl std::ops::Mul<Pos2> for TSTransform {
|
||||
}
|
||||
|
||||
/// Transforms the rectangle.
|
||||
impl std::ops::Mul<Rect> for TSTransform {
|
||||
impl core::ops::Mul<Rect> for TSTransform {
|
||||
type Output = Rect;
|
||||
|
||||
#[inline]
|
||||
@@ -128,7 +128,7 @@ impl std::ops::Mul<Rect> for TSTransform {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<Self> for TSTransform {
|
||||
impl core::ops::Mul<Self> for TSTransform {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
use std::fmt;
|
||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
|
||||
use crate::Vec2b;
|
||||
|
||||
@@ -322,7 +322,7 @@ impl Vec2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Index<usize> for Vec2 {
|
||||
impl core::ops::Index<usize> for Vec2 {
|
||||
type Output = f32;
|
||||
|
||||
#[inline(always)]
|
||||
@@ -335,7 +335,7 @@ impl std::ops::Index<usize> for Vec2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<usize> for Vec2 {
|
||||
impl core::ops::IndexMut<usize> for Vec2 {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, index: usize) -> &mut f32 {
|
||||
match index {
|
||||
@@ -514,7 +514,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_vec2() {
|
||||
use std::f32::consts::TAU;
|
||||
use core::f32::consts::TAU;
|
||||
|
||||
assert_eq!(Vec2::ZERO.angle(), 0.0);
|
||||
assert_eq!(Vec2::angled(0.0).angle(), 0.0);
|
||||
@@ -547,7 +547,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_vec2_normalized() {
|
||||
fn generate_spiral(n: usize, start: Vec2, end: Vec2) -> impl Iterator<Item = Vec2> {
|
||||
let angle_step = 2.0 * std::f32::consts::PI / n as f32;
|
||||
let angle_step = 2.0 * core::f32::consts::PI / n as f32;
|
||||
let radius_step = (end.length() - start.length()) / n as f32;
|
||||
|
||||
(0..n).map(move |i| {
|
||||
|
||||
@@ -67,7 +67,7 @@ impl From<[bool; 2]> for Vec2b {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Index<usize> for Vec2b {
|
||||
impl core::ops::Index<usize> for Vec2b {
|
||||
type Output = bool;
|
||||
|
||||
#[inline(always)]
|
||||
@@ -80,7 +80,7 @@ impl std::ops::Index<usize> for Vec2b {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::IndexMut<usize> for Vec2b {
|
||||
impl core::ops::IndexMut<usize> for Vec2b {
|
||||
#[inline(always)]
|
||||
fn index_mut(&mut self, index: usize) -> &mut bool {
|
||||
match index {
|
||||
@@ -91,7 +91,7 @@ impl std::ops::IndexMut<usize> for Vec2b {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Not for Vec2b {
|
||||
impl core::ops::Not for Vec2b {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user