diff --git a/Cargo.toml b/Cargo.toml index 6e3c44b20..124719eff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -307,6 +307,7 @@ set_contains_or_insert = "warn" single_char_pattern = "warn" single_match_else = "warn" single_option_map = "warn" +std_instead_of_core = "warn" str_split_at_newline = "warn" str_to_string = "warn" string_add = "warn" diff --git a/crates/ecolor/src/color32.rs b/crates/ecolor/src/color32.rs index f444b860d..68a8fc3d6 100644 --- a/crates/ecolor/src/color32.rs +++ b/crates/ecolor/src/color32.rs @@ -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 for Color32 { +impl core::ops::Index for Color32 { type Output = u8; #[inline] @@ -47,7 +47,7 @@ impl std::ops::Index for Color32 { } } -impl std::ops::IndexMut for Color32 { +impl core::ops::IndexMut 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:?}"); } } diff --git a/crates/ecolor/src/hex_color_runtime.rs b/crates/ecolor/src/hex_color_runtime.rs index 21e07ffc4..5acca2ef7 100644 --- a/crates/ecolor/src/hex_color_runtime.rs +++ b/crates/ecolor/src/hex_color_runtime.rs @@ -3,7 +3,7 @@ //! Supports the 3, 4, 6, and 8-digit formats, according to the specification in //! -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); diff --git a/crates/ecolor/src/rgba.rs b/crates/ecolor/src/rgba.rs index 98c3ce408..ecb8cb1d0 100644 --- a/crates/ecolor/src/rgba.rs +++ b/crates/ecolor/src/rgba.rs @@ -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 for Rgba { +impl core::ops::Index for Rgba { type Output = f32; #[inline] @@ -18,7 +18,7 @@ impl std::ops::Index for Rgba { } } -impl std::ops::IndexMut for Rgba { +impl core::ops::IndexMut for Rgba { #[inline] fn index_mut(&mut self, index: usize) -> &mut f32 { &mut self.0[index] @@ -27,20 +27,20 @@ impl std::ops::IndexMut for Rgba { /// Deterministically hash an `f32`, treating all NANs as equal, and ignoring the sign of zero. #[inline] -pub(crate) fn f32_hash(state: &mut H, f: f32) { +pub(crate) fn f32_hash(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(&self, state: &mut H) { + fn hash(&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 for Rgba { +impl core::ops::Mul for Rgba { type Output = Self; #[inline] @@ -261,7 +261,7 @@ impl std::ops::Mul for Rgba { } } -impl std::ops::Mul for f32 { +impl core::ops::Mul 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:?}"); } } diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index c10645bea..a971097a0 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -7,7 +7,7 @@ #![warn(missing_docs)] // Let's keep `epi` well-documented. #[cfg(target_arch = "wasm32")] -use std::any::Any; +use core::any::Any; #[cfg(not(target_arch = "wasm32"))] #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] @@ -41,7 +41,7 @@ pub type EventLoopBuilderHook = Box) #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] pub type WindowBuilderHook = Box egui::ViewportBuilder>; -type DynError = Box; +type DynError = Box; /// This is how your app is created. /// @@ -73,7 +73,7 @@ pub struct CreationContext<'s> { /// The `get_proc_address` wrapper of underlying GL context #[cfg(feature = "glow")] pub get_proc_address: - Option *const std::ffi::c_void + Send + Sync>>, + Option *const core::ffi::c_void + Send + Sync>>, /// The underlying WGPU render state. /// @@ -231,8 +231,8 @@ pub trait App { // Settings: /// Time between automatic calls to [`Self::save`] - fn auto_save_interval(&self) -> std::time::Duration { - std::time::Duration::from_secs(30) + fn auto_save_interval(&self) -> core::time::Duration { + core::time::Duration::from_secs(30) } /// Background color values for the app, e.g. what is sent to `gl.clearColor`. @@ -621,8 +621,8 @@ impl Default for Renderer { } #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] -impl std::fmt::Display for Renderer { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for Renderer { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { #[cfg(feature = "glow")] Self::Glow => "glow".fmt(f), @@ -634,7 +634,7 @@ impl std::fmt::Display for Renderer { } #[cfg(any(feature = "glow", feature = "wgpu_no_default_features"))] -impl std::str::FromStr for Renderer { +impl core::str::FromStr for Renderer { type Err = String; fn from_str(name: &str) -> Result { diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index 0e7259177..55caffdd6 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -503,7 +503,7 @@ pub fn run_ui_native( #[derive(Debug)] pub enum Error { /// Something went wrong in user code when creating the app. - AppCreation(Box), + AppCreation(Box), /// An error from [`winit`]. #[cfg(not(target_arch = "wasm32"))] @@ -519,7 +519,7 @@ pub enum Error { /// An error from [`glutin`] when using [`glow`]. #[cfg(all(feature = "glow", not(target_arch = "wasm32")))] - NoGlutinConfigs(glutin::config::ConfigTemplate, Box), + NoGlutinConfigs(glutin::config::ConfigTemplate, Box), /// An error from [`glutin`] when using [`glow`]. #[cfg(feature = "glow")] @@ -530,7 +530,7 @@ pub enum Error { Wgpu(egui_wgpu::WgpuError), } -impl std::error::Error for Error {} +impl core::error::Error for Error {} #[cfg(not(target_arch = "wasm32"))] impl From for Error { @@ -572,8 +572,8 @@ impl From for Error { } } -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::AppCreation(err) => write!(f, "app creation error: {err}"), @@ -614,4 +614,4 @@ impl std::fmt::Display for Error { } /// Short for `Result`. -pub type Result = std::result::Result; +pub type Result = core::result::Result; diff --git a/crates/eframe/src/native/app_icon.rs b/crates/eframe/src/native/app_icon.rs index 85be6754b..9fdeb30e0 100644 --- a/crates/eframe/src/native/app_icon.rs +++ b/crates/eframe/src/native/app_icon.rs @@ -123,7 +123,7 @@ fn set_app_icon_windows(icon_data: &IconData) -> AppIconStatus { ) .is_err() { - return std::ptr::null_mut(); + return core::ptr::null_mut(); } // SAFETY: Creating an HICON which should be readonly on our data. diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 10d64932d..b81225638 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -83,7 +83,7 @@ pub fn viewport_builder( } } - match std::mem::take(&mut native_options.window_builder) { + match core::mem::take(&mut native_options.window_builder) { Some(hook) => hook(viewport_builder), None => viewport_builder, } @@ -310,7 +310,7 @@ impl EpiIntegration { } self.pending_full_output.append(full_output); - std::mem::take(&mut self.pending_full_output) + core::mem::take(&mut self.pending_full_output) } /// Let the app tick its logic without showing any ui, @@ -354,7 +354,7 @@ impl EpiIntegration { app: &mut dyn epi::App, new_input: egui::RawInput, ) -> egui::RawInput { - let mut raw_input = std::mem::take(&mut self.pending_raw_input); + let mut raw_input = core::mem::take(&mut self.pending_raw_input); raw_input.append(new_input); // The new input wins where they overlap raw_input.time = Some(self.beginning.elapsed().as_secs_f64()); @@ -379,7 +379,7 @@ impl EpiIntegration { pub fn post_rendering(&mut self, window: &winit::window::Window) { profiling::function_scope!(); - if std::mem::take(&mut self.is_first_frame) { + if core::mem::take(&mut self.is_first_frame) { // We keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279 window.set_visible(true); } diff --git a/crates/eframe/src/native/event_loop_context.rs b/crates/eframe/src/native/event_loop_context.rs index 810db8e1f..d2081543d 100644 --- a/crates/eframe/src/native/event_loop_context.rs +++ b/crates/eframe/src/native/event_loop_context.rs @@ -1,4 +1,4 @@ -use std::cell::Cell; +use core::cell::Cell; use winit::event_loop::ActiveEventLoop; thread_local! { @@ -14,7 +14,7 @@ impl EventLoopGuard { cell.get().is_none(), "Attempted to set a new event loop while one is already set" ); - cell.set(Some(std::ptr::from_ref::(event_loop))); + cell.set(Some(core::ptr::from_ref::(event_loop))); }); Self } diff --git a/crates/eframe/src/native/file_storage.rs b/crates/eframe/src/native/file_storage.rs index 830fdcc24..f6f4ef477 100644 --- a/crates/eframe/src/native/file_storage.rs +++ b/crates/eframe/src/native/file_storage.rs @@ -44,10 +44,10 @@ pub fn storage_dir(app_id: &str) -> Option { #[cfg(all(windows, not(target_vendor = "uwp")))] #[expect(unsafe_code)] fn roaming_appdata() -> Option { + use core::ptr; + use core::slice; use std::ffi::OsString; use std::os::windows::ffi::OsStringExt as _; - use std::ptr; - use std::slice; use windows_sys::Win32::Foundation::S_OK; use windows_sys::Win32::System::Com::CoTaskMemFree; @@ -66,7 +66,7 @@ fn roaming_appdata() -> Option { SHGetKnownFolderPath( &FOLDERID_RoamingAppData, KF_FLAG_DONT_VERIFY as u32, - std::ptr::null_mut(), + core::ptr::null_mut(), &mut path_raw, ) }; diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 908cc8c26..1b9469cfd 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -8,7 +8,8 @@ #![expect(clippy::undocumented_unsafe_blocks)] #![expect(clippy::unwrap_used)] -use std::{cell::RefCell, num::NonZeroU32, rc::Rc, sync::Arc, time::Instant}; +use core::{cell::RefCell, num::NonZeroU32}; +use std::{rc::Rc, sync::Arc, time::Instant}; use egui_winit::ActionRequested; use glutin::{ @@ -152,7 +153,7 @@ impl Viewport { egui_winit::process_viewport_commands( egui_ctx, &mut self.info, - std::mem::take(&mut self.deferred_commands), + core::mem::take(&mut self.deferred_commands), window, &mut self.actions_requested, ); @@ -338,7 +339,7 @@ impl<'app> GlowWinitApp<'app> { log::warn!("set_cursor_hittest(false) failed: {err}"); } - let app_creator = std::mem::take(&mut self.app_creator) + let app_creator = core::mem::take(&mut self.app_creator) .expect("Single-use AppCreator has unexpectedly already been taken"); crate::maybe_attach_inspection_plugin(&integration.egui_ctx, Some(self.app_name.clone())); @@ -1408,7 +1409,7 @@ impl GlutinWindowContext { } } - fn get_proc_address(&self, addr: &std::ffi::CStr) -> *const std::ffi::c_void { + fn get_proc_address(&self, addr: &core::ffi::CStr) -> *const core::ffi::c_void { self.gl_config.display().get_proc_address(addr) } diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 345cc3e2c..53979591d 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -1,4 +1,5 @@ -use std::time::{Duration, Instant}; +use core::time::Duration; +use std::time::Instant; use winit::{ application::ApplicationHandler, @@ -41,7 +42,7 @@ fn create_event_loop(native_options: &mut epi::NativeOptions) -> Result( mut native_options: epi::NativeOptions, f: impl FnOnce(&mut EventLoop, epi::NativeOptions) -> R, ) -> Result { - thread_local!(static EVENT_LOOP: std::cell::RefCell>> = const { std::cell::RefCell::new(None) }); + thread_local!(static EVENT_LOOP: core::cell::RefCell>> = const { core::cell::RefCell::new(None) }); EVENT_LOOP.with(|event_loop| { // Since we want to reference NativeOptions when creating the EventLoop we can't @@ -550,7 +551,7 @@ impl<'a> EframeWinitApplication<'a> { pub fn pump_eframe_app( &mut self, event_loop: &mut EventLoop, - timeout: Option, + timeout: Option, ) -> EframePumpStatus { use winit::platform::pump_events::{EventLoopExtPumpEvents as _, PumpStatus}; diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 343c2234a..4a94a5d49 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -5,7 +5,8 @@ //! There is a bunch of improvements we could do, //! like removing a bunch of `unwraps`. -use std::{cell::RefCell, num::NonZeroU32, rc::Rc, sync::Arc, time::Instant}; +use core::{cell::RefCell, num::NonZeroU32}; +use std::{rc::Rc, sync::Arc, time::Instant}; use egui_winit::ActionRequested; use parking_lot::Mutex; @@ -309,7 +310,7 @@ impl<'app> WgpuWinitApp<'app> { egui_winit.init_accesskit(event_loop, &window, event_loop_proxy); } - let app_creator = std::mem::take(&mut self.app_creator) + let app_creator = core::mem::take(&mut self.app_creator) .expect("Single-use AppCreator has unexpectedly already been taken"); crate::maybe_attach_inspection_plugin(&egui_ctx, Some(self.app_name.clone())); @@ -1040,7 +1041,7 @@ impl Viewport { egui_winit::process_viewport_commands( egui_ctx, &mut self.info, - std::mem::take(&mut self.deferred_commands), + core::mem::take(&mut self.deferred_commands), window, &mut self.actions_requested, ); diff --git a/crates/eframe/src/native/winit_integration.rs b/crates/eframe/src/native/winit_integration.rs index 9aa356de2..5e767201e 100644 --- a/crates/eframe/src/native/winit_integration.rs +++ b/crates/eframe/src/native/winit_integration.rs @@ -25,7 +25,7 @@ pub fn is_invisible_or_minimized(window: &Window) -> bool { pub fn sleep_if_invisible_or_minimized(window: Option<&Window>) { if window.is_some_and(is_invisible_or_minimized) { profiling::scope!("minimized_sleep"); - std::thread::sleep(std::time::Duration::from_millis(10)); + std::thread::sleep(core::time::Duration::from_millis(10)); } } diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index b774bcb1f..548bdf4b5 100644 --- a/crates/eframe/src/web/app_runner.rs +++ b/crates/eframe/src/web/app_runner.rs @@ -344,7 +344,7 @@ impl AppRunner { /// Paint the results of the last call to [`Self::logic`]. pub fn paint(&mut self) { - let clipped_primitives = std::mem::take(&mut self.clipped_primitives); + let clipped_primitives = core::mem::take(&mut self.clipped_primitives); if let Some(clipped_primitives) = clipped_primitives { let mut screenshot_commands = vec![]; diff --git a/crates/eframe/src/web/dropped_file.rs b/crates/eframe/src/web/dropped_file.rs index 45e454cc5..2924e6d46 100644 --- a/crates/eframe/src/web/dropped_file.rs +++ b/crates/eframe/src/web/dropped_file.rs @@ -1,8 +1,5 @@ -use std::{ - future::Future, - path::{Path, PathBuf}, - pin::Pin, -}; +use core::{future::Future, pin::Pin}; +use std::path::{Path, PathBuf}; #[derive(Debug)] pub(crate) struct WebFile { diff --git a/crates/eframe/src/web/input.rs b/crates/eframe/src/web/input.rs index 62723e8fa..bd0195646 100644 --- a/crates/eframe/src/web/input.rs +++ b/crates/eframe/src/web/input.rs @@ -32,7 +32,7 @@ pub fn primary_touch_pos( event: &web_sys::TouchEvent, ) -> Option<(egui::Pos2, web_sys::Touch)> { // On touchend we don't get anything in `touches`, but we still get `changed_touches`, so include those: - let all_touches: Vec<_> = std::iter::chain( + let all_touches: Vec<_> = core::iter::chain( (0..event.touches().length()).filter_map(|i| event.touches().get(i)), (0..event.changed_touches().length()).filter_map(|i| event.changed_touches().get(i)), ) diff --git a/crates/eframe/src/web/text_agent.rs b/crates/eframe/src/web/text_agent.rs index b80882769..d9a12347b 100644 --- a/crates/eframe/src/web/text_agent.rs +++ b/crates/eframe/src/web/text_agent.rs @@ -1,7 +1,8 @@ //! The text agent is a hidden `` element used to capture //! IME and mobile keyboard input events. -use std::{cell::RefCell, rc::Rc}; +use core::cell::RefCell; +use std::rc::Rc; use wasm_bindgen::prelude::*; @@ -366,7 +367,7 @@ impl InputState { &self, text: &str, prefix_len_chars: usize, - ) -> Option> { + ) -> Option> { let selection_start = self.input.selection_start().unwrap_or(None)? as usize; let selection_end = self.input.selection_end().unwrap_or(None)? as usize; @@ -444,7 +445,7 @@ impl InputState { } fn longest_common_prefix_length(a: &str, b: &str) -> usize { - std::iter::zip(a.chars(), b.chars()) + core::iter::zip(a.chars(), b.chars()) .take_while(|(a, b)| a == b) .count() } diff --git a/crates/eframe/src/web/web_painter_wgpu.rs b/crates/eframe/src/web/web_painter_wgpu.rs index 273675475..afb4ee2f9 100644 --- a/crates/eframe/src/web/web_painter_wgpu.rs +++ b/crates/eframe/src/web/web_painter_wgpu.rs @@ -368,7 +368,7 @@ impl WebPainter for WebPainterWgpu { // Submit the commands: both the main buffer and user-defined ones. render_state .queue - .submit(std::iter::chain(user_cmd_bufs, [encoder.finish()])); + .submit(core::iter::chain(user_cmd_bufs, [encoder.finish()])); if let Some((frame, capture_buffer)) = frame_and_capture_buffer { if let Some(capture_buffer) = capture_buffer diff --git a/crates/eframe/src/web/web_runner.rs b/crates/eframe/src/web/web_runner.rs index 2bf842ab0..528855192 100644 --- a/crates/eframe/src/web/web_runner.rs +++ b/crates/eframe/src/web/web_runner.rs @@ -1,4 +1,5 @@ -use std::{cell::RefCell, rc::Rc}; +use core::cell::RefCell; +use std::rc::Rc; use wasm_bindgen::prelude::*; @@ -107,7 +108,7 @@ impl WebRunner { fn unsubscribe_from_all_events(&self) { let events_to_unsubscribe: Vec<_> = - std::mem::take(&mut *self.events_to_unsubscribe.borrow_mut()); + core::mem::take(&mut *self.events_to_unsubscribe.borrow_mut()); if !events_to_unsubscribe.is_empty() { log::debug!("Unsubscribing from {} events", events_to_unsubscribe.len()); @@ -139,7 +140,7 @@ impl WebRunner { /// Returns `None` if there has been a panic, or if we have been destroyed. /// In that case, just return to JS. - pub(crate) fn try_lock(&self) -> Option> { + pub(crate) fn try_lock(&self) -> Option> { if self.panic_handler.has_panicked() { // Unsubscribe from all events so that we don't get any more callbacks // that will try to access the poisoned runner. @@ -147,7 +148,7 @@ impl WebRunner { None } else { let lock = self.app_runner.try_borrow_mut().ok()?; - std::cell::RefMut::filter_map(lock, |lock| -> Option<&mut AppRunner> { lock.as_mut() }) + core::cell::RefMut::filter_map(lock, |lock| -> Option<&mut AppRunner> { lock.as_mut() }) .ok() } } @@ -158,9 +159,9 @@ impl WebRunner { /// and return `None` if this runner has panicked. pub fn app_mut( &self, - ) -> Option> { + ) -> Option> { self.try_lock() - .map(|lock| std::cell::RefMut::map(lock, |runner| runner.app_mut::())) + .map(|lock| core::cell::RefMut::map(lock, |runner| runner.app_mut::())) } /// Convenience function to reduce boilerplate and ensure that all event handlers diff --git a/crates/egui-wgpu/src/capture.rs b/crates/egui-wgpu/src/capture.rs index c5519e8a6..54ddeb884 100644 --- a/crates/egui-wgpu/src/capture.rs +++ b/crates/egui-wgpu/src/capture.rs @@ -255,7 +255,7 @@ struct BufferPadding { impl BufferPadding { fn new(width: u32) -> Self { - let bytes_per_pixel = std::mem::size_of::() as u32; + let bytes_per_pixel = core::mem::size_of::() as u32; let unpadded_bytes_per_row = width * bytes_per_pixel; let padded_bytes_per_row = wgpu::util::align_to(unpadded_bytes_per_row, wgpu::COPY_BYTES_PER_ROW_ALIGNMENT); diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index 195167177..1eb975aee 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -358,8 +358,8 @@ fn wgpu_config_impl_send_sync() { assert_send_sync::(); } -impl std::fmt::Debug for WgpuConfiguration { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for WgpuConfiguration { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Self { surface, wgpu_setup, @@ -486,7 +486,7 @@ pub fn adapter_info_summary(info: &wgpu::AdapterInfo) -> String { // > name: "Apple M1 Pro", device_type: IntegratedGpu, backend: Metal, driver: "", driver_info: "" // > name: "ANGLE (Apple, Apple M1 Pro, OpenGL 4.1)", device_type: IntegratedGpu, backend: Gl, driver: "", driver_info: "" - use std::fmt::Write as _; + use core::fmt::Write as _; let mut summary = format!("backend: {backend:?}, device_type: {device_type:?}"); diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index 2ff9f7e4a..de8808de3 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -1,4 +1,5 @@ -use std::{borrow::Cow, num::NonZeroU64, ops::Range}; +use core::{num::NonZeroU64, ops::Range}; +use std::borrow::Cow; use ahash::HashMap; use bytemuck::Zeroable as _; @@ -299,7 +300,9 @@ impl Renderer { visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Buffer { has_dynamic_offset: false, - min_binding_size: NonZeroU64::new(std::mem::size_of::() as _), + min_binding_size: NonZeroU64::new( + core::mem::size_of::() as _ + ), ty: wgpu::BufferBindingType::Uniform, }, count: None, @@ -434,9 +437,9 @@ impl Renderer { }; const VERTEX_BUFFER_START_CAPACITY: wgpu::BufferAddress = - (std::mem::size_of::() * 1024) as _; + (core::mem::size_of::() * 1024) as _; const INDEX_BUFFER_START_CAPACITY: wgpu::BufferAddress = - (std::mem::size_of::() * 1024 * 3) as _; + (core::mem::size_of::() * 1024 * 3) as _; Self { pipeline, @@ -962,7 +965,7 @@ impl Renderer { self.index_buffer.slices.clear(); - let required_index_buffer_size = (std::mem::size_of::() * index_count) as u64; + let required_index_buffer_size = (core::mem::size_of::() * index_count) as u64; if self.index_buffer.capacity < required_index_buffer_size { // Resize index buffer if needed. self.index_buffer.capacity = @@ -989,7 +992,7 @@ impl Renderer { for epaint::ClippedPrimitive { primitive, .. } in paint_jobs { match primitive { Primitive::Mesh(mesh) => { - let size = mesh.indices.len() * std::mem::size_of::(); + let size = mesh.indices.len() * core::mem::size_of::(); let slice = index_offset..(size + index_offset); index_buffer_staging .slice(slice.clone()) @@ -1006,7 +1009,8 @@ impl Renderer { self.vertex_buffer.slices.clear(); - let required_vertex_buffer_size = (std::mem::size_of::() * vertex_count) as u64; + let required_vertex_buffer_size = + (core::mem::size_of::() * vertex_count) as u64; if self.vertex_buffer.capacity < required_vertex_buffer_size { // Resize vertex buffer if needed. self.vertex_buffer.capacity = @@ -1034,7 +1038,7 @@ impl Renderer { for epaint::ClippedPrimitive { primitive, .. } in paint_jobs { match primitive { Primitive::Mesh(mesh) => { - let size = mesh.vertices.len() * std::mem::size_of::(); + let size = mesh.vertices.len() * core::mem::size_of::(); let slice = vertex_offset..(size + vertex_offset); vertex_buffer_staging .slice(slice.clone()) diff --git a/crates/egui-wgpu/src/setup.rs b/crates/egui-wgpu/src/setup.rs index f2733a6e7..3909a9b53 100644 --- a/crates/egui-wgpu/src/setup.rs +++ b/crates/egui-wgpu/src/setup.rs @@ -9,7 +9,7 @@ use std::sync::Arc; /// Automatically implemented for all types that satisfy the bounds /// (including [`winit::event_loop::OwnedDisplayHandle`]). pub trait EguiDisplayHandle: - wgpu::rwh::HasDisplayHandle + std::fmt::Debug + Send + Sync + 'static + wgpu::rwh::HasDisplayHandle + core::fmt::Debug + Send + Sync + 'static { /// Clone into a `Box` for [`wgpu::InstanceDescriptor::display`]. fn clone_for_wgpu(&self) -> Box; @@ -27,7 +27,7 @@ impl Clone for Box { impl EguiDisplayHandle for T where - T: wgpu::rwh::HasDisplayHandle + Clone + std::fmt::Debug + Send + Sync + 'static, + T: wgpu::rwh::HasDisplayHandle + Clone + core::fmt::Debug + Send + Sync + 'static, { fn clone_for_wgpu(&self) -> Box { Box::new(self.clone()) @@ -77,8 +77,8 @@ impl WgpuSetup { } } -impl std::fmt::Debug for WgpuSetup { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for WgpuSetup { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::CreateNew(create_new) => f .debug_tuple("WgpuSetup::CreateNew") @@ -295,8 +295,8 @@ impl Clone for WgpuSetupCreateNew { } } -impl std::fmt::Debug for WgpuSetupCreateNew { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for WgpuSetupCreateNew { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Self { instance_descriptor, display_handle, diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 62b5d9197..84b32927f 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -8,8 +8,9 @@ use crate::{ RendererOptions, capture::{CaptureReceiver, CaptureSender, CaptureState, capture_channel}, }; +use core::num::NonZeroU32; use egui::{Context, Event, UserData, ViewportId, ViewportIdMap, ViewportIdSet}; -use std::{num::NonZeroU32, sync::Arc}; +use std::sync::Arc; struct SurfaceState { surface: wgpu::Surface<'static>, @@ -727,7 +728,7 @@ impl Painter { let start = web_time::Instant::now(); render_state .queue - .submit(std::iter::chain(user_cmd_bufs, [encoded])); + .submit(core::iter::chain(user_cmd_bufs, [encoded])); vsync_sec += start.elapsed().as_secs_f32(); }; diff --git a/crates/egui/src/atomics/atom_kind.rs b/crates/egui/src/atomics/atom_kind.rs index f996c173b..0dfe56069 100644 --- a/crates/egui/src/atomics/atom_kind.rs +++ b/crates/egui/src/atomics/atom_kind.rs @@ -1,7 +1,7 @@ use crate::{AtomLayout, FontSelection, Image, ImageSource, SizedAtomKind, Ui, WidgetText}; +use core::fmt::Debug; use emath::Vec2; use epaint::text::TextWrapMode; -use std::fmt::Debug; /// Args passed when sizing an [`super::Atom`] pub struct IntoSizedArgs { @@ -90,7 +90,7 @@ impl Clone for AtomKind<'_> { } impl Debug for AtomKind<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { AtomKind::Empty => write!(f, "AtomKind::Empty"), AtomKind::Text(text) => write!(f, "AtomKind::Text({text:?})"), diff --git a/crates/egui/src/atomics/atom_layout.rs b/crates/egui/src/atomics/atom_layout.rs index ceb43e048..5c7da5cc7 100644 --- a/crates/egui/src/atomics/atom_layout.rs +++ b/crates/egui/src/atomics/atom_layout.rs @@ -2,11 +2,11 @@ use crate::{ AtomKind, Atoms, Direction, FontSelection, Frame, Id, Image, IntoAtoms, Response, Sense, SizedAtom, SizedAtomKind, Stroke, Ui, Widget, text_selection::LabelSelectionState, }; +use core::ops::{Deref, DerefMut}; use emath::{Align2, GuiRounding as _, NumExt as _, Rect, Vec2}; use epaint::text::TextWrapMode; use epaint::{Color32, Galley}; use smallvec::SmallVec; -use std::ops::{Deref, DerefMut}; use std::sync::Arc; /// The `(main, cross)` axis indices for `direction`, for indexing a [`Vec2`] (0 = x, 1 = y). @@ -557,7 +557,7 @@ impl<'atom> SizedAtomLayout<'atom> { F: FnMut(SizedAtomKind<'atom>) -> SizedAtomKind<'atom>, { for kind in self.iter_kinds_mut() { - *kind = f(std::mem::take(kind)); + *kind = f(core::mem::take(kind)); } } diff --git a/crates/egui/src/atomics/atoms.rs b/crates/egui/src/atomics/atoms.rs index 460d4732c..501d879e0 100644 --- a/crates/egui/src/atomics/atoms.rs +++ b/crates/egui/src/atomics/atoms.rs @@ -1,6 +1,6 @@ use crate::{Atom, AtomKind, Image, WidgetText}; +use core::ops::{Deref, DerefMut}; use std::borrow::Cow; -use std::ops::{Deref, DerefMut}; /// A list of [`Atom`]s. /// @@ -41,7 +41,7 @@ impl<'a> Atoms<'a> { /// /// If you have weird lifetime issues with this, use [`Self::push_left`] in a loop instead. pub fn extend_left(&mut self, mut atoms: Self) { - std::mem::swap(&mut atoms.0, &mut self.0); + core::mem::swap(&mut atoms.0, &mut self.0); self.0.extend(atoms.0); } @@ -128,7 +128,7 @@ impl<'a> Atoms<'a> { pub fn map_atoms(&mut self, mut f: impl FnMut(Atom<'a>) -> Atom<'a>) { self.iter_mut() - .for_each(|atom| *atom = f(std::mem::take(atom))); + .for_each(|atom| *atom = f(core::mem::take(atom))); } pub fn map_kind(&mut self, mut f: F) @@ -136,7 +136,7 @@ impl<'a> Atoms<'a> { F: FnMut(AtomKind<'a>) -> AtomKind<'a>, { for kind in self.iter_kinds_mut() { - *kind = f(std::mem::take(kind)); + *kind = f(core::mem::take(kind)); } } diff --git a/crates/egui/src/cache/cache_storage.rs b/crates/egui/src/cache/cache_storage.rs index e0aa65e8c..b3533f4cf 100644 --- a/crates/egui/src/cache/cache_storage.rs +++ b/crates/egui/src/cache/cache_storage.rs @@ -23,18 +23,18 @@ use super::CacheTrait; /// ``` #[derive(Default)] pub struct CacheStorage { - caches: ahash::HashMap>, + caches: ahash::HashMap>, } impl CacheStorage { pub fn cache(&mut self) -> &mut Cache { let cache = self .caches - .entry(std::any::TypeId::of::()) + .entry(core::any::TypeId::of::()) .or_insert_with(|| Box::::default()); #[expect(clippy::unwrap_used)] - (cache.as_mut() as &mut dyn std::any::Any) + (cache.as_mut() as &mut dyn core::any::Any) .downcast_mut::() .unwrap() } @@ -60,8 +60,8 @@ impl Clone for CacheStorage { } } -impl std::fmt::Debug for CacheStorage { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for CacheStorage { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!( f, "FrameCacheStorage[{} caches with {} elements]", diff --git a/crates/egui/src/cache/cache_trait.rs b/crates/egui/src/cache/cache_trait.rs index 54144c724..f05713d66 100644 --- a/crates/egui/src/cache/cache_trait.rs +++ b/crates/egui/src/cache/cache_trait.rs @@ -1,6 +1,6 @@ /// A cache, storing some value for some length of time. #[expect(clippy::len_without_is_empty)] -pub trait CacheTrait: 'static + Send + Sync + std::any::Any { +pub trait CacheTrait: 'static + Send + Sync + core::any::Any { /// Call once per frame to evict cache. fn update(&mut self); diff --git a/crates/egui/src/cache/frame_cache.rs b/crates/egui/src/cache/frame_cache.rs index ae39712c7..76a58c461 100644 --- a/crates/egui/src/cache/frame_cache.rs +++ b/crates/egui/src/cache/frame_cache.rs @@ -48,7 +48,7 @@ impl FrameCache { /// or recompute and store in the cache. pub fn get(&mut self, key: Key) -> &Value where - Key: Copy + std::hash::Hash, + Key: Copy + core::hash::Hash, Computer: ComputerMut, { let hash = crate::util::hash(key); diff --git a/crates/egui/src/cache/frame_publisher.rs b/crates/egui/src/cache/frame_publisher.rs index 81ba34df6..9ca576f29 100644 --- a/crates/egui/src/cache/frame_publisher.rs +++ b/crates/egui/src/cache/frame_publisher.rs @@ -1,4 +1,4 @@ -use std::hash::Hash; +use core::hash::Hash; use super::CacheTrait; diff --git a/crates/egui/src/callstack.rs b/crates/egui/src/callstack.rs index 6b0c35380..9ec426604 100644 --- a/crates/egui/src/callstack.rs +++ b/crates/egui/src/callstack.rs @@ -1,4 +1,4 @@ -use std::fmt::Write as _; +use core::fmt::Write as _; #[derive(Clone)] struct Frame { @@ -239,7 +239,7 @@ fn test_shorten_path() { ), ("/weird/path/file.rs", "/weird/path/file.rs"), ] { - use std::str::FromStr as _; + use core::str::FromStr as _; let before = std::path::PathBuf::from_str(before).unwrap(); assert_eq!(shorten_source_file_path(&before), after); } diff --git a/crates/egui/src/containers/close_tag.rs b/crates/egui/src/containers/close_tag.rs index 3e93dbbd2..273d9e251 100644 --- a/crates/egui/src/containers/close_tag.rs +++ b/crates/egui/src/containers/close_tag.rs @@ -1,6 +1,6 @@ #[expect(unused_imports)] use crate::{Ui, UiBuilder}; -use std::sync::atomic::AtomicBool; +use core::sync::atomic::AtomicBool; /// A tag to mark a container as closable. /// @@ -18,11 +18,12 @@ impl ClosableTag { /// Set close to `true` pub fn set_close(&self) { - self.close.store(true, std::sync::atomic::Ordering::Relaxed); + self.close + .store(true, core::sync::atomic::Ordering::Relaxed); } /// Returns `true` if [`ClosableTag::set_close`] has been called. pub fn should_close(&self) -> bool { - self.close.load(std::sync::atomic::Ordering::Relaxed) + self.close.load(core::sync::atomic::Ordering::Relaxed) } } diff --git a/crates/egui/src/containers/collapsing_header.rs b/crates/egui/src/containers/collapsing_header.rs index 3e49a3bb0..498d64a51 100644 --- a/crates/egui/src/containers/collapsing_header.rs +++ b/crates/egui/src/containers/collapsing_header.rs @@ -342,7 +342,7 @@ pub fn paint_default_icon(ui: &mut Ui, openness: f32, response: &Response) { let rect = Rect::from_center_size(rect.center(), vec2(rect.width(), rect.height()) * 0.75); let rect = rect.expand(visuals.expansion); let mut points = vec![rect.left_top(), rect.right_top(), rect.center_bottom()]; - use std::f32::consts::TAU; + use core::f32::consts::TAU; let rotation = emath::Rot2::from_angle(remap(openness, 0.0..=1.0, -TAU / 4.0..=0.0)); for p in &mut points { *p = rect.center() + rotation * (*p - rect.center()); diff --git a/crates/egui/src/containers/frame.rs b/crates/egui/src/containers/frame.rs index d6f751bc2..ebef299df 100644 --- a/crates/egui/src/containers/frame.rs +++ b/crates/egui/src/containers/frame.rs @@ -143,12 +143,12 @@ pub struct Frame { #[test] fn frame_size() { assert_eq!( - std::mem::size_of::(), + core::mem::size_of::(), 32, "Frame changed size! If it shrank - good! Update this test. If it grew - bad! Try to find a way to avoid it." ); assert!( - std::mem::size_of::() <= 64, + core::mem::size_of::() <= 64, "Frame is getting way too big!" ); } diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 587c77e23..8cd545dd0 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -1,4 +1,4 @@ -use std::iter::once; +use core::iter::once; use emath::{Align, Pos2, Rect, RectAlign, Vec2, vec2}; @@ -483,12 +483,12 @@ impl<'a> Popup<'a> { RectAlign::find_best_align( #[expect(clippy::iter_on_empty_collections)] #[expect(clippy::or_fun_call)] - std::iter::chain( + core::iter::chain( once(self.rect_align), self.alternative_aligns // Need the empty slice so the iters have the same type so we can unwrap_or - .map(|a| std::iter::chain(a.iter().copied(), [].iter().copied())) - .unwrap_or(std::iter::chain( + .map(|a| core::iter::chain(a.iter().copied(), [].iter().copied())) + .unwrap_or(core::iter::chain( self.rect_align.symmetries().iter().copied(), RectAlign::MENU_ALIGNS.iter().copied(), )), diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 7b1bf87e1..54d6550ca 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -2,7 +2,7 @@ #![expect(clippy::needless_range_loop)] -use std::ops::{Add, AddAssign, BitOr, BitOrAssign}; +use core::ops::{Add, AddAssign, BitOr, BitOrAssign}; use emath::GuiRounding as _; use epaint::{Color32, Direction, Margin, Shape}; @@ -930,7 +930,7 @@ impl ScrollArea { let saved_scroll_target = content_ui .ctx() - .pass_state_mut(|state| std::mem::take(&mut state.scroll_target)); + .pass_state_mut(|state| core::mem::take(&mut state.scroll_target)); Prepared { id, @@ -985,7 +985,7 @@ impl ScrollArea { ui: &mut Ui, row_height_sans_spacing: f32, total_rows: usize, - add_contents: impl FnOnce(&mut Ui, std::ops::Range) -> R, + add_contents: impl FnOnce(&mut Ui, core::ops::Range) -> R, ) -> ScrollAreaOutput { let spacing = ui.spacing().item_spacing; let row_height_with_spacing = row_height_sans_spacing + spacing.y; @@ -1093,7 +1093,7 @@ impl Prepared { if direction_enabled[d] { let (scroll_delta, scroll_animation) = content_ui.ctx().pass_state_mut(|state| { ( - std::mem::take(&mut state.scroll_delta.0[d]), + core::mem::take(&mut state.scroll_delta.0[d]), state.scroll_delta.1, ) }); diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index b39a6ec3c..69d3f0bf0 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -921,7 +921,7 @@ impl SideResponse { } } -impl std::ops::BitAnd for SideResponse { +impl core::ops::BitAnd for SideResponse { type Output = Self; fn bitand(self, rhs: Self) -> Self::Output { @@ -932,7 +932,7 @@ impl std::ops::BitAnd for SideResponse { } } -impl std::ops::BitOrAssign for SideResponse { +impl core::ops::BitOrAssign for SideResponse { fn bitor_assign(&mut self, rhs: Self) { *self = Self { hover: self.hover || rhs.hover, diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 50f324588..45193e15e 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1,6 +1,7 @@ #![warn(missing_docs)] // Let's keep `Context` well-documented. -use std::{borrow::Cow, cell::RefCell, panic::Location, sync::Arc, time::Duration}; +use core::{cell::RefCell, panic::Location, time::Duration}; +use std::{borrow::Cow, sync::Arc}; use emath::GuiRounding as _; use epaint::{ @@ -98,7 +99,7 @@ impl ContextImpl { fn begin_pass_repaint_logic(&mut self, viewport_id: ViewportId) { let viewport = self.viewports.entry(viewport_id).or_default(); - std::mem::swap( + core::mem::swap( &mut viewport.repaint.prev_causes, &mut viewport.repaint.causes, ); @@ -264,14 +265,14 @@ pub struct RepaintCause { pub reason: Cow<'static, str>, } -impl std::fmt::Debug for RepaintCause { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for RepaintCause { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}:{} {}", self.file, self.line, self.reason) } } -impl std::fmt::Display for RepaintCause { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for RepaintCause { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}:{} {}", self.file, self.line, self.reason) } } @@ -459,7 +460,7 @@ impl ContextImpl { self.memory.begin_pass(&new_raw_input, &all_viewport_ids); - viewport.input = std::mem::take(&mut viewport.input).begin_pass( + viewport.input = core::mem::take(&mut viewport.input).begin_pass( new_raw_input, viewport.repaint.requested_immediate_repaint_prev_pass(), pixels_per_point, @@ -653,7 +654,7 @@ impl ContextImpl { } fn all_viewport_ids(&self) -> ViewportIdSet { - std::iter::chain(self.viewports.keys().copied(), [ViewportId::ROOT]).collect() + core::iter::chain(self.viewports.keys().copied(), [ViewportId::ROOT]).collect() } /// The current active viewport @@ -721,13 +722,13 @@ impl ContextImpl { #[derive(Clone)] pub struct Context(Arc>); -impl std::fmt::Debug for Context { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Context { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("Context").finish_non_exhaustive() } } -impl std::cmp::PartialEq for Context { +impl core::cmp::PartialEq for Context { fn eq(&self, other: &Self) -> bool { Arc::ptr_eq(&self.0, &other.0) } @@ -737,7 +738,7 @@ impl Default for Context { fn default() -> Self { let ctx_impl = ContextImpl { embed_viewports: true, - viewports: std::iter::once((ViewportId::ROOT, ViewportState::default())).collect(), + viewports: core::iter::once((ViewportId::ROOT, ViewportState::default())).collect(), ..Default::default() }; let ctx = Self(Arc::new(RwLock::new(ctx_impl))); @@ -847,7 +848,7 @@ impl Context { self.write(|ctx| { let viewport = ctx.viewport_for(viewport_id); viewport.output.num_completed_passes = - std::mem::take(&mut output.platform_output.num_completed_passes); + core::mem::take(&mut output.platform_output.num_completed_passes); output.platform_output.request_discard_reasons.clear(); }); @@ -929,12 +930,12 @@ impl Context { logic(self); self.write(|ctx| LogicOutput { - platform_output: std::mem::take(&mut ctx.viewport_for(viewport_id).output), + platform_output: core::mem::take(&mut ctx.viewport_for(viewport_id).output), viewport_commands: ctx .viewports .iter_mut() .filter(|(_, viewport)| !viewport.commands.is_empty()) - .map(|(&id, viewport)| (id, std::mem::take(&mut viewport.commands))) + .map(|(&id, viewport)| (id, core::mem::take(&mut viewport.commands))) .collect(), }) } @@ -1875,7 +1876,7 @@ impl Context { /// See [`Self::request_repaint_after`] for details. #[track_caller] pub fn request_repaint_after_secs(&self, seconds: f32) { - if let Ok(duration) = std::time::Duration::try_from_secs_f32(seconds) { + if let Ok(duration) = core::time::Duration::try_from_secs_f32(seconds) { self.request_repaint_after(duration); } } @@ -2058,7 +2059,7 @@ impl Context { &self, f: impl FnOnce(&mut T) -> R, ) -> Option { - let plugin = self.read(|ctx| ctx.plugins.get(std::any::TypeId::of::())); + let plugin = self.read(|ctx| ctx.plugins.get(core::any::TypeId::of::())); plugin.map(|plugin| f(plugin.lock().typed_plugin_mut())) } @@ -2070,13 +2071,13 @@ impl Context { if let Some(plugin) = self.plugin_opt() { plugin } else { - panic!("Plugin of type {:?} not found", std::any::type_name::()); + panic!("Plugin of type {:?} not found", core::any::type_name::()); } } /// Get a handle to the plugin of type `T`, if it was registered. pub fn plugin_opt(&self) -> Option> { - let plugin = self.read(|ctx| ctx.plugins.get(std::any::TypeId::of::())); + let plugin = self.read(|ctx| ctx.plugins.get(core::any::TypeId::of::())); plugin.map(TypedPluginHandle::new) } @@ -2499,7 +2500,7 @@ impl Context { #[cfg(debug_assertions)] fn debug_painting(&self) { #![expect(clippy::iter_over_hash_type)] // ok to be sloppy in debug painting - use std::fmt::Write as _; + use core::fmt::Write as _; let paint_widget = |widget: &WidgetRect, text: &str, color: Color32| { let rect = widget.interact_rect; @@ -2680,7 +2681,7 @@ impl ContextImpl { // Inform the backend of all textures that have been updated (including font atlas). let textures_delta = self.tex_manager.0.write().take_delta(); - let mut platform_output: PlatformOutput = std::mem::take(&mut viewport.output); + let mut platform_output: PlatformOutput = core::mem::take(&mut viewport.output); if self.memory.should_interrupt_ime() && let Some(ime) = &mut platform_output.ime @@ -2740,7 +2741,7 @@ impl ContextImpl { shapes }; - std::mem::swap(&mut viewport.prev_pass, &mut viewport.this_pass); + core::mem::swap(&mut viewport.prev_pass, &mut viewport.this_pass); if repaint_needed { self.request_repaint(ended_viewport_id, RepaintCause::new()); @@ -2802,7 +2803,7 @@ impl ContextImpl { // Let the primary immediate viewport handle the commands of its children too. // This can make things easier for the backend, as otherwise we may get commands // that affect a viewport while its egui logic is running. - std::mem::take(&mut viewport.commands) + core::mem::take(&mut viewport.commands) } else { vec![] }; @@ -4287,13 +4288,13 @@ fn warn_if_rect_changes_id( struct OrderedRect(Rect); impl PartialOrd for OrderedRect { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for OrderedRect { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { let lhs = self.0; let rhs = other.0; lhs.min diff --git a/crates/egui/src/data/input/dropped_file.rs b/crates/egui/src/data/input/dropped_file.rs index 0ca617fa0..e01955b9f 100644 --- a/crates/egui/src/data/input/dropped_file.rs +++ b/crates/egui/src/data/input/dropped_file.rs @@ -1,13 +1,13 @@ use std::{path::Path, sync::Arc}; #[cfg(target_arch = "wasm32")] -use std::{future::Future, pin::Pin}; +use core::{future::Future, pin::Pin}; /// A file dropped into egui. /// /// The integration owns the concrete file handle, letting egui remain independent of windowing /// backends and file APIs. -pub trait DroppedFile: std::fmt::Debug { +pub trait DroppedFile: core::fmt::Debug { /// The path of the dropped file. /// /// This is an absolute path on native platforms. On the web, it is a relative path containing diff --git a/crates/egui/src/data/input/ime_event.rs b/crates/egui/src/data/input/ime_event.rs index b814b51cd..2075b2fb9 100644 --- a/crates/egui/src/data/input/ime_event.rs +++ b/crates/egui/src/data/input/ime_event.rs @@ -14,7 +14,7 @@ pub enum ImeEvent { /// a non-empty preedit string indicates that the IME is active. Preedit { text: String, - active_range_chars: Option>, + active_range_chars: Option>, }, /// IME composition ended with this final result. diff --git a/crates/egui/src/data/input/modifiers.rs b/crates/egui/src/data/input/modifiers.rs index 2478ea343..35f895950 100644 --- a/crates/egui/src/data/input/modifiers.rs +++ b/crates/egui/src/data/input/modifiers.rs @@ -37,8 +37,8 @@ pub struct Modifiers { pub command: bool, } -impl std::fmt::Debug for Modifiers { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Modifiers { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { if self.is_none() { return write!(f, "Modifiers::NONE"); } @@ -387,7 +387,7 @@ impl Modifiers { } } -impl std::ops::BitOr for Modifiers { +impl core::ops::BitOr for Modifiers { type Output = Self; #[inline] @@ -396,7 +396,7 @@ impl std::ops::BitOr for Modifiers { } } -impl std::ops::BitOrAssign for Modifiers { +impl core::ops::BitOrAssign for Modifiers { #[inline] fn bitor_assign(&mut self, rhs: Self) { *self = *self | rhs; diff --git a/crates/egui/src/data/input/raw_input.rs b/crates/egui/src/data/input/raw_input.rs index 7135e90e0..04b20bead 100644 --- a/crates/egui/src/data/input/raw_input.rs +++ b/crates/egui/src/data/input/raw_input.rs @@ -95,7 +95,7 @@ impl Default for RawInput { fn default() -> Self { Self { viewport_id: ViewportId::ROOT, - viewports: std::iter::once((ViewportId::ROOT, Default::default())).collect(), + viewports: core::iter::once((ViewportId::ROOT, Default::default())).collect(), screen_rect: None, max_texture_side: None, time: None, @@ -134,9 +134,9 @@ impl RawInput { max_texture_side: self.max_texture_side.take(), time: self.time, predicted_dt: self.predicted_dt, - events: std::mem::take(&mut self.events), + events: core::mem::take(&mut self.events), hovered_files: self.hovered_files.clone(), - dropped_files: std::mem::take(&mut self.dropped_files), + dropped_files: core::mem::take(&mut self.dropped_files), focused: self.focused, system_theme: self.system_theme, } diff --git a/crates/egui/src/data/input/safe_area_insets.rs b/crates/egui/src/data/input/safe_area_insets.rs index 914d227c2..a170ec820 100644 --- a/crates/egui/src/data/input/safe_area_insets.rs +++ b/crates/egui/src/data/input/safe_area_insets.rs @@ -10,7 +10,7 @@ use crate::emath::Rect; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct SafeAreaInsets(pub MarginF32); -impl std::ops::Sub for Rect { +impl core::ops::Sub for Rect { type Output = Self; fn sub(self, rhs: SafeAreaInsets) -> Self::Output { diff --git a/crates/egui/src/data/input/viewport_info.rs b/crates/egui/src/data/input/viewport_info.rs index 774ca1e6e..7c5a31a58 100644 --- a/crates/egui/src/data/input/viewport_info.rs +++ b/crates/egui/src/data/input/viewport_info.rs @@ -117,7 +117,7 @@ impl ViewportInfo { Self { parent: self.parent, title: self.title.clone(), - events: std::mem::take(&mut self.events), + events: core::mem::take(&mut self.events), native_pixels_per_point: self.native_pixels_per_point, monitor_size: self.monitor_size, inner_rect: self.inner_rect, @@ -209,7 +209,7 @@ impl ViewportInfo { } #[expect(clippy::ref_option)] - fn opt_as_str(v: &Option) -> String { + fn opt_as_str(v: &Option) -> String { v.as_ref().map_or(String::new(), |v| format!("{v:?}")) } }); diff --git a/crates/egui/src/data/output.rs b/crates/egui/src/data/output.rs index ae1363641..330b7a53c 100644 --- a/crates/egui/src/data/output.rs +++ b/crates/egui/src/data/output.rs @@ -1,6 +1,6 @@ //! All the data egui returns to the backend at the end of each frame. -use std::ops::Range; +use core::ops::Range; use epaint::text::CharIndex; @@ -242,7 +242,7 @@ impl PlatformOutput { /// Take everything ephemeral (everything except `cursor_icon` and /// `cursor_image` currently) pub fn take(&mut self) -> Self { - let taken = std::mem::take(self); + let taken = core::mem::take(self); self.cursor_icon = taken.cursor_icon; // sticky between frames self.cursor_image = taken.cursor_image.clone(); // sticky between frames taken @@ -327,8 +327,8 @@ pub struct CustomCursorImage { pub hotspot: [u16; 2], } -impl std::fmt::Debug for CustomCursorImage { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for CustomCursorImage { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("CustomCursorImage") .field("size", &self.size) .field("hotspot", &self.hotspot) @@ -544,8 +544,8 @@ impl OutputEvent { } } -impl std::fmt::Debug for OutputEvent { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for OutputEvent { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Clicked(wi) => write!(f, "Clicked({wi:?})"), Self::DoubleClicked(wi) => write!(f, "DoubleClicked({wi:?})"), @@ -591,8 +591,8 @@ pub struct WidgetInfo { pub hint_text: Option, } -impl std::fmt::Debug for WidgetInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for WidgetInfo { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Self { typ, enabled, diff --git a/crates/egui/src/data/user_data.rs b/crates/egui/src/data/user_data.rs index 12d90adf7..109e47207 100644 --- a/crates/egui/src/data/user_data.rs +++ b/crates/egui/src/data/user_data.rs @@ -1,4 +1,5 @@ -use std::{any::Any, sync::Arc}; +use core::any::Any; +use std::sync::Arc; /// A wrapper around `dyn Any`, used for passing custom user data /// to [`crate::ViewportCommand::Screenshot`]. @@ -30,8 +31,8 @@ impl PartialEq for UserData { impl Eq for UserData {} -impl std::hash::Hash for UserData { - fn hash(&self, state: &mut H) { +impl core::hash::Hash for UserData { + fn hash(&self, state: &mut H) { self.data.as_ref().map(Arc::as_ptr).hash(state); } } @@ -57,7 +58,7 @@ impl<'de> serde::Deserialize<'de> for UserData { impl serde::de::Visitor<'_> for UserDataVisitor { type Value = UserData; - fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter.write_str("a None value") } diff --git a/crates/egui/src/debug_text.rs b/crates/egui/src/debug_text.rs index 64d06ddac..17c3d6990 100644 --- a/crates/egui/src/debug_text.rs +++ b/crates/egui/src/debug_text.rs @@ -26,7 +26,7 @@ pub fn print(ctx: &Context, text: impl Into) { return; } - let location = std::panic::Location::caller(); + let location = core::panic::Location::caller(); let location = format!("{}:{}", location.file(), location.line()); let plugin = ctx.plugin::(); @@ -58,7 +58,7 @@ impl Plugin for DebugTextPlugin { } fn on_end_pass(&mut self, ui: &mut Ui) { - let entries = std::mem::take(&mut self.entries); + let entries = core::mem::take(&mut self.entries); Self::paint_entries(ui, entries); } } diff --git a/crates/egui/src/drag_and_drop.rs b/crates/egui/src/drag_and_drop.rs index 305effec9..5629f260a 100644 --- a/crates/egui/src/drag_and_drop.rs +++ b/crates/egui/src/drag_and_drop.rs @@ -1,4 +1,5 @@ -use std::{any::Any, sync::Arc}; +use core::any::Any; +use std::sync::Arc; use crate::{Context, CursorIcon, Plugin, Ui}; diff --git a/crates/egui/src/id.rs b/crates/egui/src/id.rs index e7bb4b2e2..c9d05465e 100644 --- a/crates/egui/src/id.rs +++ b/crates/egui/src/id.rs @@ -1,6 +1,6 @@ // TODO(emilk): have separate types `PositionId` and `UniqueId`. ? -use std::num::NonZeroU64; +use core::num::NonZeroU64; use crate::{AsIdSalt, IdSalt}; @@ -8,9 +8,9 @@ use crate::{AsIdSalt, IdSalt}; /// /// This is all types implementing `Hash` and `Debug`, /// which includes things like string, integers, tuples of those, etc. -pub trait AsId: std::hash::Hash + std::fmt::Debug {} +pub trait AsId: core::hash::Hash + core::fmt::Debug {} -impl AsId for T {} +impl AsId for T {} /// egui tracks widgets frame-to-frame using [`Id`]s. /// @@ -75,7 +75,7 @@ impl Id { /// Generate a child [`Id`] by salting the parent [`Id`] with the given argument. pub fn with(self, salt: impl AsIdSalt) -> Self { - use std::hash::{BuildHasher as _, Hasher as _}; + use core::hash::{BuildHasher as _, Hasher as _}; let mut hasher = ahash::RandomState::with_seeds(1, 2, 3, 4).build_hasher(); hasher.write_u64(self.value()); hasher.write_u64(IdSalt::new(&salt).value()); @@ -124,8 +124,8 @@ impl Id { } } -impl std::fmt::Debug for Id { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Id { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { if *self == Self::NULL { return write!(f, "Id::NULL"); } @@ -204,8 +204,8 @@ mod id_source { #[test] fn id_size() { - assert_eq!(std::mem::size_of::(), 8); - assert_eq!(std::mem::size_of::>(), 8); + assert_eq!(core::mem::size_of::(), 8); + assert_eq!(core::mem::size_of::>(), 8); } #[cfg(test)] diff --git a/crates/egui/src/id_salt.rs b/crates/egui/src/id_salt.rs index 486dda239..2540d1e0e 100644 --- a/crates/egui/src/id_salt.rs +++ b/crates/egui/src/id_salt.rs @@ -1,12 +1,12 @@ -use std::num::NonZeroU64; +use core::num::NonZeroU64; /// Types that can be converted to an [`IdSalt`]. /// /// This is all types implementing `Hash` and `Debug`, /// which includes things like string, integers, tuples of those, etc. -pub trait AsIdSalt: std::hash::Hash + std::fmt::Debug {} +pub trait AsIdSalt: core::hash::Hash + core::fmt::Debug {} -impl AsIdSalt for T {} +impl AsIdSalt for T {} /// Uniquely identifies a child widget within a parent widget. /// @@ -57,8 +57,8 @@ impl IdSalt { } } -impl std::fmt::Debug for IdSalt { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for IdSalt { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { #[cfg(debug_assertions)] if let Some(source) = id_salt_source::get(*self) { return write!(f, "IdSalt::new({source})"); diff --git a/crates/egui/src/input_state/mod.rs b/crates/egui/src/input_state/mod.rs index 36d6f9bc9..854c1fead 100644 --- a/crates/egui/src/input_state/mod.rs +++ b/crates/egui/src/input_state/mod.rs @@ -13,10 +13,8 @@ use crate::{ }, input_state::wheel_state::WheelState, }; -use std::{ - collections::{BTreeMap, HashSet}, - time::Duration, -}; +use core::time::Duration; +use std::collections::{BTreeMap, HashSet}; pub use crate::Key; pub use touch_state::MultiTouchInfo; diff --git a/crates/egui/src/input_state/touch_state.rs b/crates/egui/src/input_state/touch_state.rs index 578e45e69..833de4238 100644 --- a/crates/egui/src/input_state/touch_state.rs +++ b/crates/egui/src/input_state/touch_state.rs @@ -1,4 +1,5 @@ -use std::{collections::BTreeMap, fmt::Debug}; +use core::fmt::Debug; +use std::collections::BTreeMap; use crate::{ Event, RawInput, TouchId, TouchPhase, @@ -305,7 +306,7 @@ impl TouchState { impl Debug for TouchState { // This outputs less clutter than `#[derive(Debug)]`: - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { for (id, touch) in &self.active_touches { f.write_fmt(format_args!("#{id:?}: {touch:#?}\n"))?; } diff --git a/crates/egui/src/interaction.rs b/crates/egui/src/interaction.rs index 68ec86a50..e625fc298 100644 --- a/crates/egui/src/interaction.rs +++ b/crates/egui/src/interaction.rs @@ -274,7 +274,7 @@ pub(crate) fn interact( let drag_order = hits.drag.and_then(|w| order(w.id)).unwrap_or(0); let top_interactive_order = click_order.max(drag_order); - let mut hovered: IdSet = std::iter::chain(&hits.click, &hits.drag) + let mut hovered: IdSet = core::iter::chain(&hits.click, &hits.drag) .map(|w| w.id) .collect(); diff --git a/crates/egui/src/layers.rs b/crates/egui/src/layers.rs index 6fa9274ee..462bb0142 100644 --- a/crates/egui/src/layers.rs +++ b/crates/egui/src/layers.rs @@ -96,8 +96,8 @@ impl LayerId { } } -impl std::fmt::Debug for LayerId { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for LayerId { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Self { order, id } = self; write!(f, "LayerId {{ {order:?} {id:?} }}") } diff --git a/crates/egui/src/load.rs b/crates/egui/src/load.rs index c02f37c5c..f3acbf6af 100644 --- a/crates/egui/src/load.rs +++ b/crates/egui/src/load.rs @@ -55,12 +55,11 @@ mod bytes_loader; mod texture_loader; -use std::{ - borrow::Cow, +use core::{ fmt::{Debug, Display}, ops::Deref, - sync::Arc, }; +use std::{borrow::Cow, sync::Arc}; use ahash::HashMap; @@ -108,13 +107,13 @@ impl LoadError { detected_format.as_ref().map_or(0, |s| s.len()) } Self::Loading(message) => message.len(), - _ => std::mem::size_of::(), + _ => core::mem::size_of::(), } } } impl Display for LoadError { - 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::NoImageLoaders => f.write_str( "No image loaders are installed. If you're trying to load some images \ @@ -136,9 +135,9 @@ impl Display for LoadError { } } -impl std::error::Error for LoadError {} +impl core::error::Error for LoadError {} -pub type Result = std::result::Result; +pub type Result = core::result::Result; /// Given as a hint for image loading requests. /// @@ -209,7 +208,7 @@ pub enum Bytes { } impl Debug for Bytes { - 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::Static(arg0) => f.debug_tuple("Static").field(&arg0.len()).finish(), Self::Shared(arg0) => f.debug_tuple("Shared").field(&arg0.len()).finish(), @@ -387,7 +386,7 @@ pub type ImageLoadResult = Result; /// An `ImageLoader` decodes raw bytes into a [`ColorImage`]. /// /// Implementations are expected to cache at least each `URI`. -pub trait ImageLoader: std::any::Any { +pub trait ImageLoader: core::any::Any { /// Unique ID of this loader. /// /// To reduce the chance of collisions, include `module_path!()` as part of this ID. diff --git a/crates/egui/src/memory/mod.rs b/crates/egui/src/memory/mod.rs index d963373b4..4910d81da 100644 --- a/crates/egui/src/memory/mod.rs +++ b/crates/egui/src/memory/mod.rs @@ -1,6 +1,6 @@ #![warn(missing_docs)] // Let's keep this file well-documented.` to memory.rs -use std::num::NonZeroUsize; +use core::num::NonZeroUsize; use ahash::{HashMap, HashSet}; use epaint::emath::TSTransform; @@ -942,7 +942,7 @@ impl Memory { if let Some(modal_layer) = self.focus().and_then(|f| f.top_modal_layer) { matches!( self.areas().compare_order(layer_id, modal_layer), - std::cmp::Ordering::Equal | std::cmp::Ordering::Greater + core::cmp::Ordering::Equal | core::cmp::Ordering::Greater ) } else { true @@ -982,7 +982,7 @@ impl Memory { if let Some(current) = self.focus().and_then(|f| f.top_modal_layer_current_frame) && matches!( self.areas().compare_order(layer_id, current), - std::cmp::Ordering::Less + core::cmp::Ordering::Less ) { return; @@ -1223,12 +1223,12 @@ impl Areas { /// Compare the order of two layers, based on the order list from last frame. /// /// May return [`std::cmp::Ordering::Equal`] if the layers are not in the order list. - pub(crate) fn compare_order(&self, a: LayerId, b: LayerId) -> std::cmp::Ordering { + pub(crate) fn compare_order(&self, a: LayerId, b: LayerId) -> core::cmp::Ordering { // Sort by layer `order` first and use `order_map` to resolve disputes. // If `order_map` only contains one layer ID, then the other one will be // lower because `None < Some(x)`. match a.order.cmp(&b.order) { - std::cmp::Ordering::Equal => self.order_map.get(&a).cmp(&self.order_map.get(&b)), + core::cmp::Ordering::Equal => self.order_map.get(&a).cmp(&self.order_map.get(&b)), cmp => cmp, } } @@ -1276,7 +1276,7 @@ impl Areas { } pub fn visible_layer_ids(&self) -> ahash::HashSet { - std::iter::chain( + core::iter::chain( &self.visible_areas_last_frame, &self.visible_areas_current_frame, ) @@ -1365,7 +1365,7 @@ impl Areas { .. } = self; - std::mem::swap(visible_areas_last_frame, visible_areas_current_frame); + core::mem::swap(visible_areas_last_frame, visible_areas_current_frame); visible_areas_current_frame.clear(); order.sort_by_key(|layer| (layer.order, wants_to_be_on_top.contains(layer))); @@ -1374,7 +1374,7 @@ impl Areas { // For all layers with sublayers, put the sublayers directly after the parent layer: // (it doesn't matter in which order we replace parents with their children) #[expect(clippy::iter_over_hash_type)] - for (parent, children) in std::mem::take(sublayers) { + for (parent, children) in core::mem::take(sublayers) { let mut moved_layers = vec![parent]; // parent first… order.retain(|l| { @@ -1483,14 +1483,14 @@ fn order_map_total_ordering() { let mut i = 0; for &[a, b] in layers.array_windows() { assert!(a.order <= b.order, "does not follow LayerId.order"); - if areas.compare_order(a, b) != std::cmp::Ordering::Equal { + if areas.compare_order(a, b) != core::cmp::Ordering::Equal { i += 1; } equivalence_classes.push(i); } assert_eq!(layers.len(), equivalence_classes.len()); - for (&l1, c1) in std::iter::zip(&layers, &equivalence_classes) { - for (&l2, c2) in std::iter::zip(&layers, &equivalence_classes) { + for (&l1, c1) in core::iter::zip(&layers, &equivalence_classes) { + for (&l2, c2) in core::iter::zip(&layers, &equivalence_classes) { assert_eq!( c1.cmp(c2), areas.compare_order(l1, l2), diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index 4b81e98cb..ab64db864 100644 --- a/crates/egui/src/painter.rs +++ b/crates/egui/src/painter.rs @@ -280,7 +280,7 @@ impl Painter { ); } - pub fn error(&self, pos: Pos2, text: impl std::fmt::Display) -> Rect { + pub fn error(&self, pos: Pos2, text: impl core::fmt::Display) -> Rect { let color = self.ctx.global_style().visuals.error_fg_color; self.debug_text(pos, Align2::LEFT_TOP, color, format!("🔥 {text}")) } @@ -416,7 +416,7 @@ impl Painter { /// Show an arrow starting at `origin` and going in the direction of `vec`, with the length `vec.length()`. pub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: impl Into) { use crate::emath::Rot2; - let rot = Rot2::from_angle(std::f32::consts::TAU / 10.0); + let rot = Rot2::from_angle(core::f32::consts::TAU / 10.0); let tip_length = vec.length() / 4.0; let tip = origin + vec; let dir = vec.normalized(); diff --git a/crates/egui/src/plugin.rs b/crates/egui/src/plugin.rs index f8f1a4468..76df0a641 100644 --- a/crates/egui/src/plugin.rs +++ b/crates/egui/src/plugin.rs @@ -10,7 +10,7 @@ use std::sync::Arc; /// Plugins should not hold a reference to the [`Context`], since this would create a cycle /// (which would prevent the [`Context`] from being dropped). #[expect(unused_variables)] -pub trait Plugin: Send + Sync + std::any::Any + 'static { +pub trait Plugin: Send + Sync + core::any::Any + 'static { /// Plugin name. /// /// Used when profiling. @@ -60,14 +60,14 @@ pub(crate) struct PluginHandle { /// Use [`Self::lock`] to access the plugin. pub struct TypedPluginHandle { handle: Arc>, - _type: std::marker::PhantomData

, + _type: core::marker::PhantomData

, } impl TypedPluginHandle

{ pub(crate) fn new(handle: Arc>) -> Self { Self { handle, - _type: std::marker::PhantomData, + _type: core::marker::PhantomData, } } @@ -77,7 +77,7 @@ impl TypedPluginHandle

{ pub fn lock(&self) -> TypedPluginGuard<'_, P> { TypedPluginGuard { guard: self.handle.lock(), - _type: std::marker::PhantomData, + _type: core::marker::PhantomData, } } } @@ -85,12 +85,12 @@ impl TypedPluginHandle

{ /// A guard that provides access to a [`Plugin`]. pub struct TypedPluginGuard<'a, P: Plugin> { guard: MutexGuard<'a, PluginHandle>, - _type: std::marker::PhantomData

, + _type: core::marker::PhantomData

, } impl TypedPluginGuard<'_, P> {} -impl std::ops::Deref for TypedPluginGuard<'_, P> { +impl core::ops::Deref for TypedPluginGuard<'_, P> { type Target = P; fn deref(&self) -> &Self::Target { @@ -98,7 +98,7 @@ impl std::ops::Deref for TypedPluginGuard<'_, P> { } } -impl std::ops::DerefMut for TypedPluginGuard<'_, P> { +impl core::ops::DerefMut for TypedPluginGuard<'_, P> { fn deref_mut(&mut self) -> &mut Self::Target { self.guard.typed_plugin_mut() } @@ -111,7 +111,7 @@ impl PluginHandle { })) } - fn plugin_type_id(&self) -> std::any::TypeId { + fn plugin_type_id(&self) -> core::any::TypeId { (*self.plugin).type_id() } @@ -120,13 +120,13 @@ impl PluginHandle { } fn typed_plugin(&self) -> &P { - (self.plugin.as_ref() as &dyn std::any::Any) + (self.plugin.as_ref() as &dyn core::any::Any) .downcast_ref::

() .expect("PluginHandle: plugin is not of the expected type") } pub fn typed_plugin_mut(&mut self) -> &mut P { - (self.plugin.as_mut() as &mut dyn std::any::Any) + (self.plugin.as_mut() as &mut dyn core::any::Any) .downcast_mut::

() .expect("PluginHandle: plugin is not of the expected type") } @@ -135,7 +135,7 @@ impl PluginHandle { /// User-registered plugins. #[derive(Clone, Default)] pub(crate) struct Plugins { - plugins: HashMap>>, + plugins: HashMap>>, plugins_ordered: PluginsOrdered, } @@ -215,7 +215,7 @@ impl Plugins { true } - pub fn get(&self, type_id: std::any::TypeId) -> Option>> { + pub fn get(&self, type_id: core::any::TypeId) -> Option>> { self.plugins.get(&type_id).cloned() } } diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 5ba7b8943..e206594ad 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -1,4 +1,5 @@ -use std::{any::Any, sync::Arc}; +use core::any::Any; +use std::sync::Arc; use crate::{ Context, CursorIcon, Id, LayerId, PointerButton, Popup, PopupKind, Sense, Tooltip, Ui, @@ -77,7 +78,7 @@ pub struct Response { #[test] fn test_response_size() { assert_eq!( - std::mem::size_of::(), + core::mem::size_of::(), 88, "Keep Response small, because we create them often, and we want to keep it lean and fast" ); @@ -1112,7 +1113,7 @@ impl Response { /// ``` /// /// Now `draw_vec2(ui, foo).hovered` is true if either [`DragValue`](crate::DragValue) were hovered. -impl std::ops::BitOr for Response { +impl core::ops::BitOr for Response { type Output = Self; fn bitor(self, rhs: Self) -> Self { @@ -1133,7 +1134,7 @@ impl std::ops::BitOr for Response { /// if response.hovered() { ui.label("You hovered at least one of the widgets"); } /// # }); /// ``` -impl std::ops::BitOrAssign for Response { +impl core::ops::BitOrAssign for Response { fn bitor_assign(&mut self, rhs: Self) { *self = self.union(rhs); } diff --git a/crates/egui/src/sense.rs b/crates/egui/src/sense.rs index c3b3af7f2..1283f320e 100644 --- a/crates/egui/src/sense.rs +++ b/crates/egui/src/sense.rs @@ -22,8 +22,8 @@ bitflags::bitflags! { } } -impl std::fmt::Debug for Sense { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Sense { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "Sense {{")?; if self.senses_click() { write!(f, " click")?; diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 953cd4b9a..f6df21f09 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -1,11 +1,12 @@ //! egui theme (spacing, colors, etc). +use core::ops::RangeInclusive; use emath::Align; use epaint::{ CornerRadius, FontColorTransferFunction, Shadow, Stroke, TextOptions, text::{FontTweak, FontVariationAxis, HintingTarget, SmoothHinting}, }; -use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc}; +use std::{collections::BTreeMap, sync::Arc}; use crate::{ ComboBox, CursorIcon, FontFamily, FontId, Grid, Margin, Response, RichText, TextWrapMode, @@ -47,8 +48,8 @@ impl NumberFormatter { } } -impl std::fmt::Debug for NumberFormatter { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for NumberFormatter { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("NumberFormatter") } } @@ -93,8 +94,8 @@ pub enum TextStyle { Name(std::sync::Arc), } -impl std::fmt::Display for TextStyle { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for TextStyle { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Small => "Small".fmt(f), Self::Body => "Body".fmt(f), @@ -192,8 +193,8 @@ impl From for FontSelection { #[derive(Clone, Default)] pub struct StyleModifier(Option>); -impl std::fmt::Debug for StyleModifier { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for StyleModifier { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("StyleModifier") } } @@ -2695,7 +2696,7 @@ impl DebugOptions { } // TODO(emilk): improve and standardize -fn two_drag_values(value: &mut Vec2, range: std::ops::RangeInclusive) -> impl Widget + '_ { +fn two_drag_values(value: &mut Vec2, range: core::ops::RangeInclusive) -> impl Widget + '_ { move |ui: &mut crate::Ui| { ui.horizontal(|ui| { ui.add( @@ -2764,8 +2765,8 @@ impl NumericColorSpace { } } -impl std::fmt::Display for NumericColorSpace { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for NumericColorSpace { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::GammaByte => write!(f, "U8"), Self::Linear => write!(f, "F"), diff --git a/crates/egui/src/text_selection/cursor_range.rs b/crates/egui/src/text_selection/cursor_range.rs index 4229756db..f811b2e5e 100644 --- a/crates/egui/src/text_selection/cursor_range.rs +++ b/crates/egui/src/text_selection/cursor_range.rs @@ -49,9 +49,9 @@ impl CCursorRange { } /// The range of selected character indices. - pub fn as_sorted_char_range(&self) -> std::ops::Range { + pub fn as_sorted_char_range(&self) -> core::ops::Range { let [start, end] = self.sorted_cursors(); - std::ops::Range { + core::ops::Range { start: start.index, end: end.index, } diff --git a/crates/egui/src/text_selection/label_text_selection.rs b/crates/egui/src/text_selection/label_text_selection.rs index 80cc90c8a..4adcf59ab 100644 --- a/crates/egui/src/text_selection/label_text_selection.rs +++ b/crates/egui/src/text_selection/label_text_selection.rs @@ -47,8 +47,8 @@ fn pos_in_galley(galley: &Galley, ccursor: CCursor) -> Pos2 { galley.pos_from_cursor(ccursor).center() } -impl std::fmt::Debug for WidgetTextCursor { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for WidgetTextCursor { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Self { widget_id, ccursor, @@ -271,7 +271,7 @@ impl ViewportLabelSelectionState { self.is_dragging = false; } - let text_to_copy = std::mem::take(&mut self.text_to_copy); + let text_to_copy = core::mem::take(&mut self.text_to_copy); if !text_to_copy.is_empty() { ui.copy_text(text_to_copy); } diff --git a/crates/egui/src/text_selection/text_cursor_state.rs b/crates/egui/src/text_selection/text_cursor_state.rs index f88368f22..7ab88ec97 100644 --- a/crates/egui/src/text_selection/text_cursor_state.rs +++ b/crates/egui/src/text_selection/text_cursor_state.rs @@ -294,7 +294,7 @@ pub fn char_index_from_byte_index(input: &str, byte_index: ByteIndex) -> CharInd CharIndex(input.chars().count()) } -pub fn slice_char_range(s: &str, char_range: std::ops::Range) -> &str { +pub fn slice_char_range(s: &str, char_range: core::ops::Range) -> &str { assert!( char_range.start <= char_range.end, "Invalid range, start must be less than end, but start = {}, end = {}", diff --git a/crates/egui/src/text_selection/visuals.rs b/crates/egui/src/text_selection/visuals.rs index 5b41fd902..79e38dccb 100644 --- a/crates/egui/src/text_selection/visuals.rs +++ b/crates/egui/src/text_selection/visuals.rs @@ -139,8 +139,8 @@ pub(crate) fn paint_ime_preedit_text_visuals( painter: &Painter, galley: &Arc, row_height: f32, - preedit_range: std::ops::Range, - mut relative_active_range: Option>, + preedit_range: core::ops::Range, + mut relative_active_range: Option>, time_since_last_interaction: f64, ) { /// Instead of implementing [`PartialOrd`] and [`Ord`] for [`CCursor`] to @@ -150,7 +150,7 @@ pub(crate) fn paint_ime_preedit_text_visuals( /// These traits are intentionally not implemented because /// [`CCursor::prefer_next_row`] makes it difficult to define a clear /// ordering between two [`CCursor`]s. - fn is_cursor_range_empty(range: &std::ops::Range) -> bool { + fn is_cursor_range_empty(range: &core::ops::Range) -> bool { range.start.index == range.end.index } diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index d6a390377..9021d2d03 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1,7 +1,8 @@ #![warn(missing_docs)] // Let's keep `Ui` well-documented. #![expect(clippy::use_self)] -use std::{any::Any, ops::Deref, sync::Arc}; +use core::{any::Any, ops::Deref}; +use std::sync::Arc; use crate::containers::menu; use crate::widget_style::{HasClasses as _, ROOT_CLASS}; @@ -1984,7 +1985,7 @@ impl Ui { /// but is shown to the user in fractions of one Tau (i.e. fractions of one turn). /// The angle is NOT wrapped, so the user may select, for instance 2𝞃 (720°) pub fn drag_angle_tau(&mut self, radians: &mut f32) -> Response { - use std::f32::consts::TAU; + use core::f32::consts::TAU; let mut taus = *radians / TAU; let mut response = self.add(DragValue::new(&mut taus).speed(0.01).suffix("τ")); @@ -2599,7 +2600,7 @@ impl Ui { let column_width = (self.available_width() - total_spacing) / (NUM_COL as f32); let top_left = self.cursor().min; - let mut columns = std::array::from_fn(|col_idx| { + let mut columns = core::array::from_fn(|col_idx| { let pos = top_left + vec2((col_idx as f32) * (column_width + spacing), 0.0); let child_rect = Rect::from_min_max( pos, diff --git a/crates/egui/src/ui_stack.rs b/crates/egui/src/ui_stack.rs index f43834dba..f6b4865be 100644 --- a/crates/egui/src/ui_stack.rs +++ b/crates/egui/src/ui_stack.rs @@ -1,5 +1,5 @@ +use core::{any::Any, iter::FusedIterator}; use std::sync::Arc; -use std::{any::Any, iter::FusedIterator}; use crate::widget_style::Classes; use epaint::Color32; diff --git a/crates/egui/src/util/fixed_cache.rs b/crates/egui/src/util/fixed_cache.rs index c0f8662a2..b2d2e45dd 100644 --- a/crates/egui/src/util/fixed_cache.rs +++ b/crates/egui/src/util/fixed_cache.rs @@ -16,15 +16,15 @@ where } } -impl std::fmt::Debug for FixedCache { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for FixedCache { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "Cache") } } impl FixedCache where - K: std::hash::Hash + PartialEq, + K: core::hash::Hash + PartialEq, { pub fn get(&self, key: &K) -> Option<&V> { let bucket = (hash(key) % (FIXED_CACHE_SIZE as u64)) as usize; diff --git a/crates/egui/src/util/id_type_map.rs b/crates/egui/src/util/id_type_map.rs index 76f0da5d7..d384a883b 100644 --- a/crates/egui/src/util/id_type_map.rs +++ b/crates/egui/src/util/id_type_map.rs @@ -3,7 +3,8 @@ // For non-serializable types, these simply return `None`. // This will also allow users to pick their own serialization format per type. -use std::{any::Any, sync::Arc}; +use core::any::Any; +use std::sync::Arc; // ----------------------------------------------------------------------------------------------- /// Like [`std::any::TypeId`], but can be serialized and deserialized. @@ -14,7 +15,7 @@ pub struct TypeId(u64); impl TypeId { #[inline] pub fn of() -> Self { - std::any::TypeId::of::().into() + core::any::TypeId::of::().into() } #[inline(always)] @@ -23,9 +24,9 @@ impl TypeId { } } -impl From for TypeId { +impl From for TypeId { #[inline] - fn from(id: std::any::TypeId) -> Self { + fn from(id: core::any::TypeId) -> Self { Self(epaint::util::hash(id)) } } @@ -113,8 +114,8 @@ impl Clone for Element { } } -impl std::fmt::Debug for Element { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Element { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match &self { Self::Value { value, .. } => f .debug_struct("Element::Value") @@ -314,7 +315,7 @@ fn from_ron_str(ron: &str) -> Option { Err(_err) => { log::warn!( "egui: Failed to deserialize {} from memory: {}, ron error: {:?}", - std::any::type_name::(), + core::any::type_name::(), _err, ron ); @@ -578,7 +579,7 @@ impl IdTypeMap { pub fn remove_temp(&mut self, id: Id) -> Option { let key = RawKey::new::(id); let mut element = self.map.remove(&key)?; - Some(std::mem::take(element.get_mut_temp()?)) + Some(core::mem::take(element.get_mut_temp()?)) } /// Remove a temporary value given a raw key. diff --git a/crates/egui/src/util/undoer.rs b/crates/egui/src/util/undoer.rs index a2eec6599..cbac10d76 100644 --- a/crates/egui/src/util/undoer.rs +++ b/crates/egui/src/util/undoer.rs @@ -67,8 +67,8 @@ pub struct Undoer { flux: Option>, } -impl std::fmt::Debug for Undoer { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Undoer { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Self { undos, redos, .. } = self; f.debug_struct("Undoer") .field("undo count", &undos.len()) diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index 962b065a3..e04f9d505 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -120,13 +120,13 @@ pub struct ViewportId(pub Id); // We implement `PartialOrd` and `Ord` so we can use `ViewportId` in a `BTreeMap`, // which allows predicatable iteration order, frame-to-frame. impl PartialOrd for ViewportId { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for ViewportId { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.value().cmp(&other.0.value()) } } @@ -138,8 +138,8 @@ impl Default for ViewportId { } } -impl std::fmt::Debug for ViewportId { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for ViewportId { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { self.0.short_debug_format().fmt(f) } } @@ -198,8 +198,8 @@ impl IconData { } } -impl std::fmt::Debug for IconData { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for IconData { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("IconData") .field("width", &self.width) .field("height", &self.height) @@ -1275,7 +1275,7 @@ pub struct ViewportOutput { /// but if you haven't, you can use this instead. /// /// If the duration is zero, schedule a repaint immediately. - pub repaint_delay: std::time::Duration, + pub repaint_delay: core::time::Duration, } impl ViewportOutput { diff --git a/crates/egui/src/widget_style.rs b/crates/egui/src/widget_style.rs index f3c5e5bd0..f6239cae9 100644 --- a/crates/egui/src/widget_style.rs +++ b/crates/egui/src/widget_style.rs @@ -256,7 +256,7 @@ impl HasClasses for Classes { } } -impl std::fmt::Display for Classes { +impl core::fmt::Display for Classes { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.classes.iter().for_each(|class| { let _ = f.write_str(class.as_str()); diff --git a/crates/egui/src/widget_text.rs b/crates/egui/src/widget_text.rs index c8e803cbc..9281253ad 100644 --- a/crates/egui/src/widget_text.rs +++ b/crates/egui/src/widget_text.rs @@ -1,5 +1,5 @@ +use core::fmt::Formatter; use epaint::text::{IntoTag, TextFormat, VariationCoords}; -use std::fmt::Formatter; use std::{borrow::Cow, sync::Arc}; use crate::{ @@ -539,8 +539,8 @@ pub enum WidgetText { Galley(Arc), } -impl std::fmt::Debug for WidgetText { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for WidgetText { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { let text = self.text(); match self { Self::Text(_) => write!(f, "Text({text:?})"), diff --git a/crates/egui/src/widgets/drag_value.rs b/crates/egui/src/widgets/drag_value.rs index 7f1140bd9..81f686fe1 100644 --- a/crates/egui/src/widgets/drag_value.rs +++ b/crates/egui/src/widgets/drag_value.rs @@ -3,8 +3,8 @@ use crate::{ Modifiers, NumExt as _, Response, RichText, Sense, TextEdit, TextWrapMode, Ui, Widget, WidgetInfo, emath, text, }; +use core::{cmp::Ordering, ops::RangeInclusive}; use emath::Vec2; -use std::{cmp::Ordering, ops::RangeInclusive}; // ---------------------------------------------------------------------------- @@ -780,7 +780,7 @@ mod tests { macro_rules! total_assert_eq { ($a:expr, $b:expr) => { assert!( - matches!($a.total_cmp(&$b), std::cmp::Ordering::Equal), + matches!($a.total_cmp(&$b), core::cmp::Ordering::Equal), "{} != {}", $a, $b diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index 30a5997ec..0618e8661 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -1,4 +1,5 @@ -use std::{borrow::Cow, slice::Iter, sync::Arc, time::Duration}; +use core::{slice::Iter, time::Duration}; +use std::{borrow::Cow, sync::Arc}; use emath::{Align, Float as _, GuiRounding as _, NumExt as _, Rot2}; use epaint::{ @@ -607,8 +608,8 @@ pub enum ImageSource<'a> { }, } -impl std::fmt::Debug for ImageSource<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for ImageSource<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { ImageSource::Bytes { uri, .. } | ImageSource::Uri(uri) => uri.as_ref().fmt(f), ImageSource::Texture(st) => st.id.fmt(f), diff --git a/crates/egui/src/widgets/progress_bar.rs b/crates/egui/src/widgets/progress_bar.rs index 444f6088c..ed697cc4d 100644 --- a/crates/egui/src/widgets/progress_bar.rs +++ b/crates/egui/src/widgets/progress_bar.rs @@ -163,7 +163,7 @@ impl Widget for ProgressBar { if animate && !has_custom_cr { let n_points = 20; let time = ui.input(|i| i.time); - let start_angle = time * std::f64::consts::TAU; + let start_angle = time * core::f64::consts::TAU; let end_angle = start_angle + 240f64.to_radians() * time.sin(); let circle_radius = half_height - 2.0; let points: Vec = (0..n_points) diff --git a/crates/egui/src/widgets/slider.rs b/crates/egui/src/widgets/slider.rs index b5ce4fc55..796489421 100644 --- a/crates/egui/src/widgets/slider.rs +++ b/crates/egui/src/widgets/slider.rs @@ -1,6 +1,6 @@ #![expect(clippy::needless_pass_by_value)] // False positives with `impl ToString` -use std::ops::RangeInclusive; +use core::ops::RangeInclusive; use crate::{ Color32, DragValue, EventFilter, Key, Label, MINUS_CHAR_STR, NumExt as _, Pos2, Rangef, Rect, diff --git a/crates/egui/src/widgets/spinner.rs b/crates/egui/src/widgets/spinner.rs index 25820a06e..d378fd3b1 100644 --- a/crates/egui/src/widgets/spinner.rs +++ b/crates/egui/src/widgets/spinner.rs @@ -45,7 +45,7 @@ impl Spinner { let radius = (rect.height().min(rect.width()) / 2.0) - 2.0; let n_points = (radius.round() as u32).clamp(8, 128); let time = ui.input(|i| i.time); - let start_angle = time * std::f64::consts::TAU; + let start_angle = time * core::f64::consts::TAU; let end_angle = start_angle + 240f64.to_radians() * time.sin(); let points: Vec = (0..n_points) .map(|i| { diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 96bd3ca01..41220ed81 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -1008,7 +1008,7 @@ impl TextEdit<'_> { fn mask_if_password(is_password: bool, text: &str) -> String { fn mask_password(text: &str) -> String { - std::iter::repeat_n( + core::iter::repeat_n( epaint::text::PASSWORD_REPLACEMENT_CHAR, text.chars().count(), ) @@ -1084,7 +1084,7 @@ fn events( Selection(CCursorRange), ImeComposition { cursor_range: CCursorRange, - active_range: Option>, + active_range: Option>, }, ImeCompositionCursorRange(CCursorRange), } diff --git a/crates/egui/src/widgets/text_edit/state.rs b/crates/egui/src/widgets/text_edit/state.rs index 61ffb21ea..d17532753 100644 --- a/crates/egui/src/widgets/text_edit/state.rs +++ b/crates/egui/src/widgets/text_edit/state.rs @@ -95,7 +95,7 @@ pub(crate) enum TextEditCursorPurpose { /// irrelevant. /// /// When `None`, no active range is displayed. - active_range: Option>, + active_range: Option>, }, } diff --git a/crates/egui/src/widgets/text_edit/text_buffer.rs b/crates/egui/src/widgets/text_edit/text_buffer.rs index 1fada9626..f09843e86 100644 --- a/crates/egui/src/widgets/text_edit/text_buffer.rs +++ b/crates/egui/src/widgets/text_edit/text_buffer.rs @@ -1,4 +1,5 @@ -use std::{borrow::Cow, ops::Range}; +use core::ops::Range; +use std::borrow::Cow; use epaint::{ Galley, @@ -237,7 +238,7 @@ pub trait TextBuffer { /// } /// } /// ``` - fn type_id(&self) -> std::any::TypeId; + fn type_id(&self) -> core::any::TypeId; } impl TextBuffer for String { @@ -282,11 +283,11 @@ impl TextBuffer for String { } fn take(&mut self) -> String { - std::mem::take(self) + core::mem::take(self) } - fn type_id(&self) -> std::any::TypeId { - std::any::TypeId::of::() + fn type_id(&self) -> core::any::TypeId { + core::any::TypeId::of::() } } @@ -316,11 +317,11 @@ impl TextBuffer for Cow<'_, str> { } fn take(&mut self) -> String { - std::mem::take(self).into_owned() + core::mem::take(self).into_owned() } - fn type_id(&self) -> std::any::TypeId { - std::any::TypeId::of::>() + fn type_id(&self) -> core::any::TypeId { + core::any::TypeId::of::>() } } @@ -340,8 +341,8 @@ impl TextBuffer for &str { fn delete_char_range(&mut self, _ch_range: Range) {} - fn type_id(&self) -> std::any::TypeId { - std::any::TypeId::of::<&str>() + fn type_id(&self) -> core::any::TypeId { + core::any::TypeId::of::<&str>() } } diff --git a/crates/egui_demo_app/src/accessibility_inspector.rs b/crates/egui_demo_app/src/accessibility_inspector.rs index 91da6c653..c28bde2fa 100644 --- a/crates/egui_demo_app/src/accessibility_inspector.rs +++ b/crates/egui_demo_app/src/accessibility_inspector.rs @@ -1,4 +1,4 @@ -use std::mem; +use core::mem; use accesskit::{Action, ActionRequest}; use accesskit_consumer::{FilterResult, Node, NodeId, Tree, TreeChangeHandler}; @@ -168,7 +168,7 @@ impl AccessibilityInspectorPlugin { ui.horizontal_wrapped(|ui| { // Iterate through all possible actions via the `Action::n` helper. let mut current_action = 0; - let all_actions = std::iter::from_fn(|| { + let all_actions = core::iter::from_fn(|| { let action = Action::n(current_action); current_action += 1; action diff --git a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs index b6ba60df9..97ba1d3d2 100644 --- a/crates/egui_demo_app/src/apps/custom3d_wgpu.rs +++ b/crates/egui_demo_app/src/apps/custom3d_wgpu.rs @@ -1,6 +1,6 @@ #![expect(clippy::unwrap_used)] // TODO(emilk): avoid unwraps -use std::num::NonZeroU64; +use core::num::NonZeroU64; use eframe::{ egui_wgpu::wgpu::util::DeviceExt as _, diff --git a/crates/egui_demo_app/src/apps/fractal_clock.rs b/crates/egui_demo_app/src/apps/fractal_clock.rs index 43ed3fb8b..783e8d2c1 100644 --- a/crates/egui_demo_app/src/apps/fractal_clock.rs +++ b/crates/egui_demo_app/src/apps/fractal_clock.rs @@ -1,10 +1,10 @@ +use core::f32::consts::TAU; use egui::{ Color32, Painter, Pos2, Rect, Shape, Stroke, Ui, Vec2, containers::{CollapsingHeader, Frame}, emath, pos2, widgets::Slider, }; -use std::f32::consts::TAU; #[derive(PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -202,7 +202,7 @@ impl FractalClock { } } - std::mem::swap(&mut nodes, &mut new_nodes); + core::mem::swap(&mut nodes, &mut new_nodes); } self.line_count = shapes.len(); painter.extend(shapes); diff --git a/crates/egui_demo_app/src/backend_panel.rs b/crates/egui_demo_app/src/backend_panel.rs index 4d6039a85..0fb7eee0f 100644 --- a/crates/egui_demo_app/src/backend_panel.rs +++ b/crates/egui_demo_app/src/backend_panel.rs @@ -160,9 +160,9 @@ impl BackendPanel { { log::info!("Waiting 2s before requesting repaint…"); let ctx = ui.ctx().clone(); - call_after_delay(std::time::Duration::from_secs(2), move || { + call_after_delay(core::time::Duration::from_secs(2), move || { log::info!("Request a repaint in 3s…"); - ctx.request_repaint_after(std::time::Duration::from_secs(3)); + ctx.request_repaint_after(core::time::Duration::from_secs(3)); }); } @@ -525,7 +525,7 @@ impl EguiWindows { // ---------------------------------------------------------------------------- #[cfg(not(target_arch = "wasm32"))] -fn call_after_delay(delay: std::time::Duration, f: impl FnOnce() + Send + 'static) { +fn call_after_delay(delay: core::time::Duration, f: impl FnOnce() + Send + 'static) { std::thread::Builder::new() .name("call_after_delay".to_owned()) .spawn(move || { @@ -536,7 +536,7 @@ fn call_after_delay(delay: std::time::Duration, f: impl FnOnce() + Send + 'stati } #[cfg(target_arch = "wasm32")] -fn call_after_delay(delay: std::time::Duration, f: impl FnOnce() + Send + 'static) { +fn call_after_delay(delay: core::time::Duration, f: impl FnOnce() + Send + 'static) { #![expect(clippy::unwrap_used)] use wasm_bindgen::prelude::*; diff --git a/crates/egui_demo_app/src/main.rs b/crates/egui_demo_app/src/main.rs index 38da5751d..b487ab99d 100644 --- a/crates/egui_demo_app/src/main.rs +++ b/crates/egui_demo_app/src/main.rs @@ -38,7 +38,7 @@ fn main() { }); for loud_crate in ["naga", "wgpu_core", "wgpu_hal"] { if !rust_log.contains(&format!("{loud_crate}=")) { - use std::fmt::Write as _; + use core::fmt::Write as _; write!(rust_log, ",{loud_crate}=warn").ok(); } } @@ -103,7 +103,7 @@ fn start_puffin_server() { // We can store the server if we want, but in this case we just want // it to keep running. Dropping it closes the server, so let's not drop it! #[expect(clippy::mem_forget)] - std::mem::forget(puffin_server); + core::mem::forget(puffin_server); } Err(err) => { log::error!("Failed to start puffin server: {err}"); diff --git a/crates/egui_demo_app/src/wrap_app.rs b/crates/egui_demo_app/src/wrap_app.rs index 629ad6a97..8801bba23 100644 --- a/crates/egui_demo_app/src/wrap_app.rs +++ b/crates/egui_demo_app/src/wrap_app.rs @@ -127,8 +127,8 @@ impl Anchor { } } -impl std::fmt::Display for Anchor { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for Anchor { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut name = format!("{self:?}"); name.make_ascii_lowercase(); f.write_str(&name) @@ -473,8 +473,8 @@ impl WrapApp { } fn ui_file_drag_and_drop(&mut self, ctx: &egui::Context) { + use core::fmt::Write as _; use egui::{Align2, Color32, Id, LayerId, Order, TextStyle}; - use std::fmt::Write as _; // Preview hovering files: if !ctx.input(|i| i.raw.hovered_files.is_empty()) { diff --git a/crates/egui_demo_lib/benches/benchmark.rs b/crates/egui_demo_lib/benches/benchmark.rs index 36accead3..6b0eb5d4c 100644 --- a/crates/egui_demo_lib/benches/benchmark.rs +++ b/crates/egui_demo_lib/benches/benchmark.rs @@ -1,4 +1,4 @@ -use std::fmt::Write as _; +use core::fmt::Write as _; use criterion::{BatchSize, Criterion, criterion_group, criterion_main}; diff --git a/crates/egui_demo_lib/src/demo/dancing_strings.rs b/crates/egui_demo_lib/src/demo/dancing_strings.rs index 137ecc2b9..7846e0ee4 100644 --- a/crates/egui_demo_lib/src/demo/dancing_strings.rs +++ b/crates/egui_demo_lib/src/demo/dancing_strings.rs @@ -61,7 +61,7 @@ impl crate::View for DancingStrings { .map(|i| { let t = i as f64 / (n as f64); let amp = (time * speed * mode).sin() / mode; - let y = amp * (t * std::f64::consts::TAU / 2.0 * mode).sin(); + let y = amp * (t * core::f64::consts::TAU / 2.0 * mode).sin(); to_screen * pos2(t as f32, y as f32) }) .collect(); diff --git a/crates/egui_demo_lib/src/demo/demo_app_windows.rs b/crates/egui_demo_lib/src/demo/demo_app_windows.rs index a874de5b6..fc15aac16 100644 --- a/crates/egui_demo_lib/src/demo/demo_app_windows.rs +++ b/crates/egui_demo_lib/src/demo/demo_app_windows.rs @@ -13,7 +13,7 @@ struct DemoGroup { demos: Vec>, } -impl std::ops::Add for DemoGroup { +impl core::ops::Add for DemoGroup { type Output = Self; fn add(self, other: Self) -> Self { diff --git a/crates/egui_demo_lib/src/demo/misc_demo_window.rs b/crates/egui_demo_lib/src/demo/misc_demo_window.rs index 6b9584dd2..8b91fbc64 100644 --- a/crates/egui_demo_lib/src/demo/misc_demo_window.rs +++ b/crates/egui_demo_lib/src/demo/misc_demo_window.rs @@ -41,7 +41,7 @@ impl Default for MiscDemoWindow { dummy_bool: false, dummy_usize: 0, - checklist: std::array::from_fn(|i| i == 0), + checklist: core::array::from_fn(|i| i == 0), } } } @@ -184,7 +184,7 @@ impl View for MiscDemoWindow { .show(ui, |ui| { ui.horizontal(|ui| { ui.label("You can pretty easily paint your own small icons:"); - use std::f32::consts::TAU; + use core::f32::consts::TAU; let size = Vec2::splat(16.0); let (response, painter) = ui.allocate_painter(size, Sense::hover()); let rect = response.rect; @@ -264,7 +264,7 @@ pub struct Widgets { impl Default for Widgets { fn default() -> Self { Self { - angle: std::f32::consts::TAU / 3.0, + angle: core::f32::consts::TAU / 3.0, password: "hunter2".to_owned(), } } @@ -282,7 +282,7 @@ impl Widgets { ui.horizontal(|ui| { ui.label("An angle:"); ui.drag_angle(angle); - ui.label(format!("≈ {:.3}τ", *angle / std::f32::consts::TAU)) + ui.label(format!("≈ {:.3}τ", *angle / core::f32::consts::TAU)) .on_hover_text("Each τ represents one turn (τ = 2π)"); }) .response @@ -421,7 +421,7 @@ impl Repaint { ctx.request_repaint(); } if self.repaint_after_delay { - ctx.request_repaint_after(std::time::Duration::from_secs_f64(self.delay)); + ctx.request_repaint_after(core::time::Duration::from_secs_f64(self.delay)); } } } @@ -623,7 +623,7 @@ impl Tree { return Action::Delete; } - self.0 = std::mem::take(self) + self.0 = core::mem::take(self) .0 .into_iter() .enumerate() @@ -897,7 +897,7 @@ impl Default for TextRotation { impl TextRotation { pub fn ui(&mut self, ui: &mut Ui) { - ui.add(Slider::new(&mut self.angle, 0.0..=2.0 * std::f32::consts::PI).text("angle")); + ui.add(Slider::new(&mut self.angle, 0.0..=2.0 * core::f32::consts::PI).text("angle")); let default_color = if ui.visuals().dark_mode { Color32::LIGHT_GRAY diff --git a/crates/egui_demo_lib/src/demo/sliders.rs b/crates/egui_demo_lib/src/demo/sliders.rs index 7dab0f26c..d2371cafd 100644 --- a/crates/egui_demo_lib/src/demo/sliders.rs +++ b/crates/egui_demo_lib/src/demo/sliders.rs @@ -125,7 +125,7 @@ impl crate::View for Sliders { ); if ui.button("Assign PI").clicked() { - self.value = std::f64::consts::PI; + self.value = core::f64::consts::PI; } } diff --git a/crates/egui_demo_lib/src/demo/tests/grid_test.rs b/crates/egui_demo_lib/src/demo/tests/grid_test.rs index 1806eb431..7befe09e1 100644 --- a/crates/egui_demo_lib/src/demo/tests/grid_test.rs +++ b/crates/egui_demo_lib/src/demo/tests/grid_test.rs @@ -113,7 +113,7 @@ impl crate::View for GridTest { ui.end_row(); let mut dyn_text = String::from("O"); - dyn_text.extend(std::iter::repeat_n('h', self.text_length)); + dyn_text.extend(core::iter::repeat_n('h', self.text_length)); ui.label(dyn_text); ui.label("Fifth row, second column"); ui.end_row(); diff --git a/crates/egui_demo_lib/src/demo/tests/input_test.rs b/crates/egui_demo_lib/src/demo/tests/input_test.rs index e237b3e4b..ca753d650 100644 --- a/crates/egui_demo_lib/src/demo/tests/input_test.rs +++ b/crates/egui_demo_lib/src/demo/tests/input_test.rs @@ -123,7 +123,7 @@ impl crate::View for InputTest { } fn response_summary(response: &egui::Response, show_hovers: bool) -> String { - use std::fmt::Write as _; + use core::fmt::Write as _; let mut new_info = String::new(); diff --git a/crates/egui_extras/src/datepicker/button.rs b/crates/egui_extras/src/datepicker/button.rs index 42e4f900f..94770ca71 100644 --- a/crates/egui_extras/src/datepicker/button.rs +++ b/crates/egui_extras/src/datepicker/button.rs @@ -1,7 +1,7 @@ use super::popup::DatePickerPopup; +use core::ops::RangeInclusive; use egui::{Area, Button, Frame, InnerResponse, Key, Order, RichText, Ui, Widget}; use jiff::civil::Date; -use std::ops::RangeInclusive; #[derive(Default, Clone)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] diff --git a/crates/egui_extras/src/datepicker/mod.rs b/crates/egui_extras/src/datepicker/mod.rs index f1f6e58fa..1eaf37118 100644 --- a/crates/egui_extras/src/datepicker/mod.rs +++ b/crates/egui_extras/src/datepicker/mod.rs @@ -26,7 +26,7 @@ fn month_data(year: i16, month: i8) -> Vec { if start.weekday() == Weekday::Sunday { weeks.push(Week { number: ISOWeekDate::from(start).week() as u8, - days: std::mem::take(&mut week), + days: core::mem::take(&mut week), }); } start = start.tomorrow().unwrap(); diff --git a/crates/egui_extras/src/datepicker/popup.rs b/crates/egui_extras/src/datepicker/popup.rs index 5c0726e5a..52bd71be4 100644 --- a/crates/egui_extras/src/datepicker/popup.rs +++ b/crates/egui_extras/src/datepicker/popup.rs @@ -32,7 +32,7 @@ pub(crate) struct DatePickerPopup<'a> { pub calendar: bool, pub calendar_week: bool, pub highlight_weekends: bool, - pub start_end_years: Option>, + pub start_end_years: Option>, pub reverse_years: bool, pub year_scroll_to: Option, } diff --git a/crates/egui_extras/src/loaders/file_loader.rs b/crates/egui_extras/src/loaders/file_loader.rs index bdafb6553..d566628b1 100644 --- a/crates/egui_extras/src/loaders/file_loader.rs +++ b/crates/egui_extras/src/loaders/file_loader.rs @@ -1,9 +1,10 @@ use ahash::HashMap; +use core::task::Poll; use egui::{ load::{Bytes, BytesLoadResult, BytesLoader, BytesPoll, LoadError}, mutex::Mutex, }; -use std::{path::PathBuf, sync::Arc, task::Poll, thread}; +use std::{path::PathBuf, sync::Arc, thread}; #[derive(Clone)] struct File { diff --git a/crates/egui_extras/src/loaders/gif_loader.rs b/crates/egui_extras/src/loaders/gif_loader.rs index ebaf9a6b3..c1242a1f9 100644 --- a/crates/egui_extras/src/loaders/gif_loader.rs +++ b/crates/egui_extras/src/loaders/gif_loader.rs @@ -1,11 +1,12 @@ use ahash::HashMap; +use core::{mem::size_of, time::Duration}; use egui::{ ColorImage, FrameDurations, Id, decode_animated_image_uri, has_gif_magic_header, load::{BytesPoll, ImageLoadResult, ImageLoader, ImagePoll, LoadError, SizeHint}, mutex::Mutex, }; use image::AnimationDecoder as _; -use std::{io::Cursor, mem::size_of, sync::Arc, time::Duration}; +use std::{io::Cursor, sync::Arc}; /// Array of Frames and the duration for how long each frame should be shown #[derive(Debug, Clone)] diff --git a/crates/egui_extras/src/loaders/http_loader.rs b/crates/egui_extras/src/loaders/http_loader.rs index e3b4d350e..6eb1bc5ba 100644 --- a/crates/egui_extras/src/loaders/http_loader.rs +++ b/crates/egui_extras/src/loaders/http_loader.rs @@ -1,9 +1,10 @@ use ahash::HashMap; +use core::task::Poll; use egui::{ load::{Bytes, BytesLoadResult, BytesLoader, BytesPoll, LoadError}, mutex::Mutex, }; -use std::{sync::Arc, task::Poll}; +use std::sync::Arc; #[derive(Clone)] struct File { diff --git a/crates/egui_extras/src/loaders/image_loader.rs b/crates/egui_extras/src/loaders/image_loader.rs index 969ed5538..b14a57286 100644 --- a/crates/egui_extras/src/loaders/image_loader.rs +++ b/crates/egui_extras/src/loaders/image_loader.rs @@ -1,11 +1,12 @@ use ahash::HashMap; +use core::{mem::size_of, task::Poll}; use egui::{ ColorImage, decode_animated_image_uri, load::{Bytes, BytesPoll, ImageLoadResult, ImageLoader, ImagePoll, LoadError, SizeHint}, mutex::Mutex, }; use image::ImageFormat; -use std::{mem::size_of, path::Path, sync::Arc, task::Poll}; +use std::{path::Path, sync::Arc}; #[cfg(not(target_arch = "wasm32"))] use std::thread; @@ -146,7 +147,7 @@ impl ImageLoader for ImageCrateLoader { .map(Arc::new) .map_err(|err| err.to_string()); log::trace!("finished loading {uri:?}"); - cache_lock.insert(uri.into(), std::task::Poll::Ready(result.clone())); + cache_lock.insert(uri.into(), core::task::Poll::Ready(result.clone())); match result { Ok(image) => Ok(ImagePoll::Ready { image }), Err(err) => Err(LoadError::Loading(err)), diff --git a/crates/egui_extras/src/loaders/svg_loader.rs b/crates/egui_extras/src/loaders/svg_loader.rs index 3bd881fbf..91063f6b4 100644 --- a/crates/egui_extras/src/loaders/svg_loader.rs +++ b/crates/egui_extras/src/loaders/svg_loader.rs @@ -1,4 +1,5 @@ -use std::{mem::size_of, sync::Arc}; +use core::mem::size_of; +use std::sync::Arc; use ahash::HashMap; diff --git a/crates/egui_extras/src/loaders/webp_loader.rs b/crates/egui_extras/src/loaders/webp_loader.rs index 23d778358..3ecd7068a 100644 --- a/crates/egui_extras/src/loaders/webp_loader.rs +++ b/crates/egui_extras/src/loaders/webp_loader.rs @@ -1,11 +1,12 @@ use ahash::HashMap; +use core::{mem::size_of, time::Duration}; use egui::{ ColorImage, FrameDurations, Id, decode_animated_image_uri, has_webp_header, load::{BytesPoll, ImageLoadResult, ImageLoader, ImagePoll, LoadError, SizeHint}, mutex::Mutex, }; use image::{AnimationDecoder as _, ColorType, ImageDecoder as _, Rgba, codecs::webp::WebPDecoder}; -use std::{io::Cursor, mem::size_of, sync::Arc, time::Duration}; +use std::{io::Cursor, sync::Arc}; #[derive(Clone)] enum WebP { diff --git a/crates/egui_extras/src/syntax_highlighting.rs b/crates/egui_extras/src/syntax_highlighting.rs index c3981b0e2..d09151d21 100644 --- a/crates/egui_extras/src/syntax_highlighting.rs +++ b/crates/egui_extras/src/syntax_highlighting.rs @@ -514,9 +514,9 @@ struct HighlightSettings<'a>(&'a SyntectSettings); #[derive(Copy, Clone)] struct HighlightSettings<'a>(&'a ()); -impl std::hash::Hash for HighlightSettings<'_> { - fn hash(&self, state: &mut H) { - std::ptr::hash(self.0, state); +impl core::hash::Hash for HighlightSettings<'_> { + fn hash(&self, state: &mut H) { + core::ptr::hash(self.0, state); } } diff --git a/crates/egui_glow/examples/pure_glow.rs b/crates/egui_glow/examples/pure_glow.rs index c8ce705c8..17fa95b73 100644 --- a/crates/egui_glow/examples/pure_glow.rs +++ b/crates/egui_glow/examples/pure_glow.rs @@ -5,7 +5,7 @@ #![expect(clippy::undocumented_unsafe_blocks)] #![expect(unsafe_code)] -use std::num::NonZeroU32; +use core::num::NonZeroU32; use std::sync::Arc; use egui_winit::winit; @@ -146,7 +146,7 @@ impl GlutinWindowContext { self.gl_surface.swap_buffers(&self.gl_context) } - fn get_proc_address(&self, addr: &std::ffi::CStr) -> *const std::ffi::c_void { + fn get_proc_address(&self, addr: &core::ffi::CStr) -> *const core::ffi::c_void { use glutin::display::GlDisplay as _; self.gl_display.get_proc_address(addr) } @@ -154,7 +154,7 @@ impl GlutinWindowContext { #[derive(Debug)] pub enum UserEvent { - Redraw(std::time::Duration), + Redraw(core::time::Duration), } struct GlowApp { @@ -162,7 +162,7 @@ struct GlowApp { gl_window: Option, gl: Option>, egui_glow: Option, - repaint_delay: std::time::Duration, + repaint_delay: core::time::Duration, clear_color: [f32; 3], } @@ -173,7 +173,7 @@ impl GlowApp { gl_window: None, gl: None, egui_glow: None, - repaint_delay: std::time::Duration::MAX, + repaint_delay: core::time::Duration::MAX, clear_color: [0.1, 0.1, 0.1], } } diff --git a/crates/egui_glow/src/painter.rs b/crates/egui_glow/src/painter.rs index 2b2341da1..8a68de1f8 100644 --- a/crates/egui_glow/src/painter.rs +++ b/crates/egui_glow/src/painter.rs @@ -55,10 +55,10 @@ impl TextureWrapModeExt for egui::TextureWrapMode { #[derive(Debug)] pub struct PainterError(String); -impl std::error::Error for PainterError {} +impl core::error::Error for PainterError {} -impl std::fmt::Display for PainterError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for PainterError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "OpenGL: {}", self.0) } } @@ -219,7 +219,7 @@ impl Painter { let a_tc_loc = gl.get_attrib_location(program, "a_tc").unwrap(); let a_srgba_loc = gl.get_attrib_location(program, "a_srgba").unwrap(); - let stride = std::mem::size_of::() as i32; + let stride = core::mem::size_of::() as i32; let buffer_infos = vec![ vao::BufferInfo { location: a_pos_loc, diff --git a/crates/egui_glow/src/shader_version.rs b/crates/egui_glow/src/shader_version.rs index 7d0caf7fa..e34e44c68 100644 --- a/crates/egui_glow/src/shader_version.rs +++ b/crates/egui_glow/src/shader_version.rs @@ -2,7 +2,7 @@ #![expect(clippy::unwrap_used)] // TODO(emilk): avoid unwraps #![expect(unsafe_code)] -use std::convert::TryInto as _; +use core::convert::TryInto as _; /// Helper for parsing and interpreting the OpenGL shader version. #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/crates/egui_glow/src/winit.rs b/crates/egui_glow/src/winit.rs index 9d2b71310..6ec9b8215 100644 --- a/crates/egui_glow/src/winit.rs +++ b/crates/egui_glow/src/winit.rs @@ -104,8 +104,8 @@ impl EguiGlow { /// Paint the results of the last call to [`Self::run`]. pub fn paint(&mut self, window: &winit::window::Window) { - let shapes = std::mem::take(&mut self.shapes); - let mut textures_delta = std::mem::take(&mut self.textures_delta); + let shapes = core::mem::take(&mut self.shapes); + let mut textures_delta = core::mem::take(&mut self.textures_delta); #[expect(clippy::iter_over_hash_type)] // Order doesn't matter here for (id, image_deltas) in textures_delta.set.drain() { diff --git a/crates/egui_inspection/src/plugin.rs b/crates/egui_inspection/src/plugin.rs index 0ae857ab1..76ad8893a 100644 --- a/crates/egui_inspection/src/plugin.rs +++ b/crates/egui_inspection/src/plugin.rs @@ -33,8 +33,8 @@ //! Note that [`serve`]'s threads hold an [`egui::Context`] clone, so the context stays alive //! for as long as the listener runs (the lifetime of the process, for a debug attach). +use core::time::Duration; use std::sync::mpsc; -use std::time::Duration; use egui::{Context, FullOutput, RawInput}; diff --git a/crates/egui_inspection/src/protocol.rs b/crates/egui_inspection/src/protocol.rs index 631e7c7b1..e95ce5cf5 100644 --- a/crates/egui_inspection/src/protocol.rs +++ b/crates/egui_inspection/src/protocol.rs @@ -136,7 +136,7 @@ pub struct EncodedPng { /// Hard cap on a single framed message. Matches the sanity limit enforced by both ends. pub const MAX_MESSAGE_BYTES: usize = 256 * 1024 * 1024; // 256 MiB -fn invalid_data(err: impl std::fmt::Display) -> io::Error { +fn invalid_data(err: impl core::fmt::Display) -> io::Error { io::Error::new(io::ErrorKind::InvalidData, err.to_string()) } diff --git a/crates/egui_kittest/src/builder.rs b/crates/egui_kittest/src/builder.rs index dc4757ee5..23109544b 100644 --- a/crates/egui_kittest/src/builder.rs +++ b/crates/egui_kittest/src/builder.rs @@ -2,8 +2,8 @@ use crate::app_kind::AppKind; #[cfg(feature = "eframe")] use crate::app_kind::AppKindEframe; use crate::{Harness, LazyRenderer, TestRenderer}; +use core::marker::PhantomData; use egui::{Pos2, Rect, Vec2}; -use std::marker::PhantomData; /// Builder for [`Harness`]. #[must_use] diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index 2a8575ef1..fa8f26311 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -26,7 +26,7 @@ pub use { kittest, }; -use std::{ +use core::{ fmt::{Debug, Display, Formatter}, time::Duration, }; @@ -47,7 +47,7 @@ pub struct ExceededMaxStepsError { } impl Display for ExceededMaxStepsError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { write!( f, "Harness::run exceeded max_steps ({}). If your expect your ui to keep repainting \ @@ -90,7 +90,7 @@ pub struct Harness<'a, State = ()> { } impl Debug for Harness<'_, State> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { self.kittest.fmt(f) } } @@ -245,7 +245,7 @@ impl<'a, State> Harness<'a, State> { /// This will call the app closure with each queued event and /// update the Harness. pub fn step(&mut self) { - let events = std::mem::take(&mut *self.queued_events.lock()); + let events = core::mem::take(&mut *self.queued_events.lock()); if events.is_empty() { self._step(false); } @@ -802,7 +802,7 @@ impl<'a, State> Harness<'a, State> { // SAFETY: `pthread_main_np` is a thread-safe libc query with no arguments. let is_main_thread = unsafe { unsafe extern "C" { - fn pthread_main_np() -> std::ffi::c_int; + fn pthread_main_np() -> core::ffi::c_int; } pthread_main_np() != 0 }; diff --git a/crates/egui_kittest/src/node.rs b/crates/egui_kittest/src/node.rs index 729fda763..285602a84 100644 --- a/crates/egui_kittest/src/node.rs +++ b/crates/egui_kittest/src/node.rs @@ -1,8 +1,8 @@ +use core::fmt::{Debug, Formatter}; use egui::accesskit::ActionRequest; use egui::mutex::Mutex; use egui::{Modifiers, PointerButton, Pos2, accesskit}; use kittest::{AccessKitNode, NodeT, debug_fmt_node}; -use std::fmt::{Debug, Formatter}; pub type EventQueue = Mutex>; @@ -14,7 +14,7 @@ pub struct Node<'tree> { } impl Debug for Node<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { debug_fmt_node(self, f) } } diff --git a/crates/egui_kittest/src/renderer.rs b/crates/egui_kittest/src/renderer.rs index 4abcf31c4..1f18a7fa3 100644 --- a/crates/egui_kittest/src/renderer.rs +++ b/crates/egui_kittest/src/renderer.rs @@ -1,5 +1,5 @@ +use core::mem; use egui::TexturesDelta; -use std::mem; pub trait TestRenderer { /// We use this to pass the glow / wgpu render state to [`eframe::Frame`]. diff --git a/crates/egui_kittest/src/snapshot.rs b/crates/egui_kittest/src/snapshot.rs index 09ce986c8..e4472219f 100644 --- a/crates/egui_kittest/src/snapshot.rs +++ b/crates/egui_kittest/src/snapshot.rs @@ -1,4 +1,4 @@ -use std::fmt::Display; +use core::fmt::Display; use std::io::ErrorKind; use std::path::PathBuf; @@ -305,7 +305,7 @@ const HOW_TO_UPDATE_SCREENSHOTS: &str = "Run `UPDATE_SNAPSHOTS=1 cargo test --all-features` to update the snapshots."; impl Display for SnapshotError { - 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::Diff { name, @@ -840,7 +840,7 @@ impl Harness<'_, State> { /// This removes the snapshot results from the harness. Useful if you e.g. want to merge it /// with the results from another harness (using [`SnapshotResults::add`]). pub fn take_snapshot_results(&mut self) -> SnapshotResults { - std::mem::take(&mut self.snapshot_results) + core::mem::take(&mut self.snapshot_results) } } @@ -872,7 +872,7 @@ impl Harness<'_, State> { pub struct SnapshotResults { errors: Vec, handled: bool, - location: std::panic::Location<'static>, + location: core::panic::Location<'static>, } impl Default for SnapshotResults { @@ -881,13 +881,13 @@ impl Default for SnapshotResults { Self { errors: Vec::new(), handled: true, // If no snapshots were added, we should consider this handled. - location: *std::panic::Location::caller(), + location: *core::panic::Location::caller(), } } } impl Display for SnapshotResults { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { if self.errors.is_empty() { write!(f, "All snapshots passed") } else { @@ -939,7 +939,7 @@ impl SnapshotResults { /// Consume this and return the list of errors. pub fn into_inner(mut self) -> Vec { self.handled = true; - std::mem::take(&mut self.errors) + core::mem::take(&mut self.errors) } /// Panics if there are any errors, displaying each. @@ -968,7 +968,7 @@ impl Drop for SnapshotResults { } thread_local! { - static UNHANDLED_SNAPSHOT_RESULTS_COUNTER: std::cell::RefCell = const { std::cell::RefCell::new(0) }; + static UNHANDLED_SNAPSHOT_RESULTS_COUNTER: core::cell::RefCell = const { core::cell::RefCell::new(0) }; } if !self.handled { diff --git a/crates/egui_kittest/src/texture_to_image.rs b/crates/egui_kittest/src/texture_to_image.rs index 289033fba..5c292c6cd 100644 --- a/crates/egui_kittest/src/texture_to_image.rs +++ b/crates/egui_kittest/src/texture_to_image.rs @@ -1,8 +1,8 @@ +use core::iter; +use core::mem::size_of; use egui_wgpu::wgpu; use egui_wgpu::wgpu::{Device, Extent3d, Queue, Texture}; use image::RgbaImage; -use std::iter; -use std::mem::size_of; use std::sync::mpsc::channel; use crate::wgpu::WAIT_TIMEOUT; diff --git a/crates/egui_kittest/src/wgpu.rs b/crates/egui_kittest/src/wgpu.rs index e5266aead..af751fe40 100644 --- a/crates/egui_kittest/src/wgpu.rs +++ b/crates/egui_kittest/src/wgpu.rs @@ -1,5 +1,5 @@ +use core::{iter::once, time::Duration}; use std::sync::Arc; -use std::{iter::once, time::Duration}; use egui::TexturesDelta; use egui_wgpu::{RenderState, ScreenDescriptor, WgpuSetup, wgpu}; @@ -230,7 +230,7 @@ impl crate::TestRenderer for WgpuTestRenderer { self.render_state .queue - .submit(std::iter::chain(user_buffers, once(encoder.finish()))); + .submit(core::iter::chain(user_buffers, once(encoder.finish()))); self.render_state .device diff --git a/crates/egui_kittest/tests/regression_tests.rs b/crates/egui_kittest/tests/regression_tests.rs index 8aad4dea1..12e66ac56 100644 --- a/crates/egui_kittest/tests/regression_tests.rs +++ b/crates/egui_kittest/tests/regression_tests.rs @@ -662,7 +662,7 @@ fn window_fixed_size_is_outer_size() { /// allowed size — they used to inherit the overflowing content rect. #[test] fn panel_rect_clamped_when_content_overflows() { - use std::cell::RefCell; + use core::cell::RefCell; let side_panel_width = 100.0_f32; let top_panel_height = 80.0_f32; @@ -723,7 +723,7 @@ fn panel_rect_clamped_when_content_overflows() { /// portion of the panel. #[test] fn collapsing_panel_must_not_grow_enclosing_window() { - use std::cell::RefCell; + use core::cell::RefCell; let window_rect: RefCell> = RefCell::new(None); let is_expanded: RefCell = RefCell::new(true); diff --git a/crates/emath/src/align.rs b/crates/emath/src/align.rs index 395323d4f..4001af4bf 100644 --- a/crates/emath/src/align.rs +++ b/crates/emath/src/align.rs @@ -274,7 +274,7 @@ impl Align2 { } } -impl std::ops::Index for Align2 { +impl core::ops::Index for Align2 { type Output = Align; #[inline(always)] @@ -283,7 +283,7 @@ impl std::ops::Index for Align2 { } } -impl std::ops::IndexMut for Align2 { +impl core::ops::IndexMut 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()) } } diff --git a/crates/emath/src/easing.rs b/crates/emath/src/easing.rs index 6a98cad80..57c439f27 100644 --- a/crates/emath/src/easing.rs +++ b/crates/emath/src/easing.rs @@ -5,7 +5,7 @@ //! All functions take a value in `[0, 1]` and return a value in `[0, 1]`. //! //! Derived from . -use std::f32::consts::PI; +use core::f32::consts::PI; use crate::fast_midpoint; diff --git a/crates/emath/src/history.rs b/crates/emath/src/history.rs index 4a49defa2..3b0d1fb56 100644 --- a/crates/emath/src/history.rs +++ b/crates/emath/src/history.rs @@ -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, max_age: f32) -> Self { + pub fn new(length_range: core::ops::Range, max_age: f32) -> Self { Self { min_len: length_range.start, max_len: length_range.end, @@ -175,8 +175,8 @@ where impl History where T: Copy, - T: std::iter::Sum, - T: std::ops::Div, + T: core::iter::Sum, + T: core::ops::Div, { #[inline] pub fn sum(&self) -> T { @@ -196,9 +196,9 @@ where impl History where T: Copy, - T: std::iter::Sum, - T: std::ops::Div, - T: std::ops::Mul, + T: core::iter::Sum, + T: core::ops::Div, + T: core::ops::Mul, { /// Average times rate. /// If you are keeping track of individual sizes of things (e.g. bytes), @@ -211,8 +211,8 @@ where impl History where T: Copy, - T: std::ops::Sub, - Vel: std::ops::Div, + T: core::ops::Sub, + Vel: core::ops::Div, { /// 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. diff --git a/crates/emath/src/lib.rs b/crates/emath/src/lib.rs index 92e34620a..1e7b3b807 100644 --- a/crates/emath/src/lib.rs +++ b/crates/emath/src/lib.rs @@ -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); diff --git a/crates/emath/src/numeric.rs b/crates/emath/src/numeric.rs index b4b6174e2..a94cfbe6d 100644 --- a/crates/emath/src/numeric.rs +++ b/crates/emath/src/numeric.rs @@ -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); diff --git a/crates/emath/src/ordered_float.rs b/crates/emath/src/ordered_float.rs index 369541fed..dc86e2472 100644 --- a/crates/emath/src/ordered_float.rs +++ b/crates/emath/src/ordered_float.rs @@ -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 OrderedFloat { } } -impl std::fmt::Debug for OrderedFloat { +impl core::fmt::Debug for OrderedFloat { #[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) } } diff --git a/crates/emath/src/pos2.rs b/crates/emath/src/pos2.rs index f67767e6b..d331769dc 100644 --- a/crates/emath/src/pos2.rs +++ b/crates/emath/src/pos2.rs @@ -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 for Pos2 { +impl core::ops::Index for Pos2 { type Output = f32; #[inline(always)] @@ -219,7 +219,7 @@ impl std::ops::Index for Pos2 { } } -impl std::ops::IndexMut for Pos2 { +impl core::ops::IndexMut for Pos2 { #[inline(always)] fn index_mut(&mut self, index: usize) -> &mut f32 { match index { diff --git a/crates/emath/src/range.rs b/crates/emath/src/range.rs index be6072c71..991659f5d 100644 --- a/crates/emath/src/range.rs +++ b/crates/emath/src/range.rs @@ -1,4 +1,4 @@ -use std::ops::{RangeFrom, RangeFull, RangeInclusive, RangeToInclusive}; +use core::ops::{RangeFrom, RangeFull, RangeInclusive, RangeToInclusive}; use crate::fast_midpoint; diff --git a/crates/emath/src/rect.rs b/crates/emath/src/rect.rs index 8fd04b431..f01387c18 100644 --- a/crates/emath/src/rect.rs +++ b/crates/emath/src/rect.rs @@ -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); diff --git a/crates/emath/src/rect_transform.rs b/crates/emath/src/rect_transform.rs index 3539efe75..05355620a 100644 --- a/crates/emath/src/rect_transform.rs +++ b/crates/emath/src/rect_transform.rs @@ -65,7 +65,7 @@ impl RectTransform { } /// Transforms the position. -impl std::ops::Mul for RectTransform { +impl core::ops::Mul for RectTransform { type Output = Pos2; fn mul(self, pos: Pos2) -> Pos2 { @@ -74,7 +74,7 @@ impl std::ops::Mul for RectTransform { } /// Transforms the position. -impl std::ops::Mul for &RectTransform { +impl core::ops::Mul for &RectTransform { type Output = Pos2; fn mul(self, pos: Pos2) -> Pos2 { diff --git a/crates/emath/src/rot2.rs b/crates/emath/src/rot2.rs index 9af0103a0..9aa4b52d7 100644 --- a/crates/emath/src/rot2.rs +++ b/crates/emath/src/rot2.rs @@ -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 for Rot2 { +impl core::ops::Mul for Rot2 { type Output = Self; #[inline] @@ -130,7 +130,7 @@ impl std::ops::Mul for Rot2 { } /// Rotates (and maybe scales) the vector. -impl std::ops::Mul for Rot2 { +impl core::ops::Mul for Rot2 { type Output = Vec2; #[inline] @@ -143,7 +143,7 @@ impl std::ops::Mul for Rot2 { } /// Scales the rotor. -impl std::ops::Mul for f32 { +impl core::ops::Mul for f32 { type Output = Rot2; #[inline] @@ -156,7 +156,7 @@ impl std::ops::Mul for f32 { } /// Scales the rotor. -impl std::ops::Mul for Rot2 { +impl core::ops::Mul for Rot2 { type Output = Self; #[inline] @@ -169,7 +169,7 @@ impl std::ops::Mul for Rot2 { } /// Scales the rotor. -impl std::ops::Div for Rot2 { +impl core::ops::Div 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); diff --git a/crates/emath/src/ts_transform.rs b/crates/emath/src/ts_transform.rs index 515f5ecd7..5d36911ed 100644 --- a/crates/emath/src/ts_transform.rs +++ b/crates/emath/src/ts_transform.rs @@ -109,7 +109,7 @@ impl TSTransform { } /// Transforms the position. -impl std::ops::Mul for TSTransform { +impl core::ops::Mul for TSTransform { type Output = Pos2; #[inline] @@ -119,7 +119,7 @@ impl std::ops::Mul for TSTransform { } /// Transforms the rectangle. -impl std::ops::Mul for TSTransform { +impl core::ops::Mul for TSTransform { type Output = Rect; #[inline] @@ -128,7 +128,7 @@ impl std::ops::Mul for TSTransform { } } -impl std::ops::Mul for TSTransform { +impl core::ops::Mul for TSTransform { type Output = Self; #[inline] diff --git a/crates/emath/src/vec2.rs b/crates/emath/src/vec2.rs index f79359df9..5422aa79b 100644 --- a/crates/emath/src/vec2.rs +++ b/crates/emath/src/vec2.rs @@ -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 for Vec2 { +impl core::ops::Index for Vec2 { type Output = f32; #[inline(always)] @@ -335,7 +335,7 @@ impl std::ops::Index for Vec2 { } } -impl std::ops::IndexMut for Vec2 { +impl core::ops::IndexMut 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 { - 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| { diff --git a/crates/emath/src/vec2b.rs b/crates/emath/src/vec2b.rs index 673f2959e..be5c36f78 100644 --- a/crates/emath/src/vec2b.rs +++ b/crates/emath/src/vec2b.rs @@ -67,7 +67,7 @@ impl From<[bool; 2]> for Vec2b { } } -impl std::ops::Index for Vec2b { +impl core::ops::Index for Vec2b { type Output = bool; #[inline(always)] @@ -80,7 +80,7 @@ impl std::ops::Index for Vec2b { } } -impl std::ops::IndexMut for Vec2b { +impl core::ops::IndexMut for Vec2b { #[inline(always)] fn index_mut(&mut self, index: usize) -> &mut bool { match index { @@ -91,7 +91,7 @@ impl std::ops::IndexMut for Vec2b { } } -impl std::ops::Not for Vec2b { +impl core::ops::Not for Vec2b { type Output = Self; #[inline] diff --git a/crates/epaint/benches/benchmark.rs b/crates/epaint/benches/benchmark.rs index 8fbfc65ea..5cafeaf0f 100644 --- a/crates/epaint/benches/benchmark.rs +++ b/crates/epaint/benches/benchmark.rs @@ -5,7 +5,7 @@ use epaint::{ Tessellator, TextureAtlas, Vec2, pos2, tessellator::Path, }; -use std::hint::black_box; +use core::hint::black_box; #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; // Much faster allocator diff --git a/crates/epaint/src/color.rs b/crates/epaint/src/color.rs index 54106c10d..8aa4f56df 100644 --- a/crates/epaint/src/color.rs +++ b/crates/epaint/src/color.rs @@ -1,4 +1,5 @@ -use std::{fmt::Debug, sync::Arc}; +use core::fmt::Debug; +use std::sync::Arc; use ecolor::Color32; use emath::{Pos2, Rect}; @@ -25,7 +26,7 @@ impl Default for ColorMode { } impl Debug for ColorMode { - 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::Solid(arg0) => f.debug_tuple("Solid").field(arg0).finish(), Self::UV(_arg0) => f.debug_tuple("UV").field(&"").finish(), diff --git a/crates/epaint/src/corner_radius.rs b/crates/epaint/src/corner_radius.rs index 07bd56c9e..dd0b432b9 100644 --- a/crates/epaint/src/corner_radius.rs +++ b/crates/epaint/src/corner_radius.rs @@ -99,7 +99,7 @@ impl CornerRadius { } } -impl std::ops::Add for CornerRadius { +impl core::ops::Add for CornerRadius { type Output = Self; #[inline] fn add(self, rhs: Self) -> Self { @@ -112,7 +112,7 @@ impl std::ops::Add for CornerRadius { } } -impl std::ops::Add for CornerRadius { +impl core::ops::Add for CornerRadius { type Output = Self; #[inline] fn add(self, rhs: u8) -> Self { @@ -125,7 +125,7 @@ impl std::ops::Add for CornerRadius { } } -impl std::ops::AddAssign for CornerRadius { +impl core::ops::AddAssign for CornerRadius { #[inline] fn add_assign(&mut self, rhs: Self) { *self = Self { @@ -137,7 +137,7 @@ impl std::ops::AddAssign for CornerRadius { } } -impl std::ops::AddAssign for CornerRadius { +impl core::ops::AddAssign for CornerRadius { #[inline] fn add_assign(&mut self, rhs: u8) { *self = Self { @@ -149,7 +149,7 @@ impl std::ops::AddAssign for CornerRadius { } } -impl std::ops::Sub for CornerRadius { +impl core::ops::Sub for CornerRadius { type Output = Self; #[inline] fn sub(self, rhs: Self) -> Self { @@ -162,7 +162,7 @@ impl std::ops::Sub for CornerRadius { } } -impl std::ops::Sub for CornerRadius { +impl core::ops::Sub for CornerRadius { type Output = Self; #[inline] fn sub(self, rhs: u8) -> Self { @@ -175,7 +175,7 @@ impl std::ops::Sub for CornerRadius { } } -impl std::ops::SubAssign for CornerRadius { +impl core::ops::SubAssign for CornerRadius { #[inline] fn sub_assign(&mut self, rhs: Self) { *self = Self { @@ -187,7 +187,7 @@ impl std::ops::SubAssign for CornerRadius { } } -impl std::ops::SubAssign for CornerRadius { +impl core::ops::SubAssign for CornerRadius { #[inline] fn sub_assign(&mut self, rhs: u8) { *self = Self { @@ -199,7 +199,7 @@ impl std::ops::SubAssign for CornerRadius { } } -impl std::ops::Div for CornerRadius { +impl core::ops::Div for CornerRadius { type Output = Self; #[inline] fn div(self, rhs: f32) -> Self { @@ -212,7 +212,7 @@ impl std::ops::Div for CornerRadius { } } -impl std::ops::DivAssign for CornerRadius { +impl core::ops::DivAssign for CornerRadius { #[inline] fn div_assign(&mut self, rhs: f32) { *self = Self { @@ -224,7 +224,7 @@ impl std::ops::DivAssign for CornerRadius { } } -impl std::ops::Mul for CornerRadius { +impl core::ops::Mul for CornerRadius { type Output = Self; #[inline] fn mul(self, rhs: f32) -> Self { @@ -237,7 +237,7 @@ impl std::ops::Mul for CornerRadius { } } -impl std::ops::MulAssign for CornerRadius { +impl core::ops::MulAssign for CornerRadius { #[inline] fn mul_assign(&mut self, rhs: f32) { *self = Self { diff --git a/crates/epaint/src/corner_radius_f32.rs b/crates/epaint/src/corner_radius_f32.rs index 0a88aaac7..ef6e597f5 100644 --- a/crates/epaint/src/corner_radius_f32.rs +++ b/crates/epaint/src/corner_radius_f32.rs @@ -111,7 +111,7 @@ impl CornerRadiusF32 { } } -impl std::ops::Add for CornerRadiusF32 { +impl core::ops::Add for CornerRadiusF32 { type Output = Self; #[inline] fn add(self, rhs: Self) -> Self { @@ -124,7 +124,7 @@ impl std::ops::Add for CornerRadiusF32 { } } -impl std::ops::AddAssign for CornerRadiusF32 { +impl core::ops::AddAssign for CornerRadiusF32 { #[inline] fn add_assign(&mut self, rhs: Self) { *self = Self { @@ -136,7 +136,7 @@ impl std::ops::AddAssign for CornerRadiusF32 { } } -impl std::ops::AddAssign for CornerRadiusF32 { +impl core::ops::AddAssign for CornerRadiusF32 { #[inline] fn add_assign(&mut self, rhs: f32) { *self = Self { @@ -148,7 +148,7 @@ impl std::ops::AddAssign for CornerRadiusF32 { } } -impl std::ops::Sub for CornerRadiusF32 { +impl core::ops::Sub for CornerRadiusF32 { type Output = Self; #[inline] fn sub(self, rhs: Self) -> Self { @@ -161,7 +161,7 @@ impl std::ops::Sub for CornerRadiusF32 { } } -impl std::ops::SubAssign for CornerRadiusF32 { +impl core::ops::SubAssign for CornerRadiusF32 { #[inline] fn sub_assign(&mut self, rhs: Self) { *self = Self { @@ -173,7 +173,7 @@ impl std::ops::SubAssign for CornerRadiusF32 { } } -impl std::ops::SubAssign for CornerRadiusF32 { +impl core::ops::SubAssign for CornerRadiusF32 { #[inline] fn sub_assign(&mut self, rhs: f32) { *self = Self { @@ -185,7 +185,7 @@ impl std::ops::SubAssign for CornerRadiusF32 { } } -impl std::ops::Div for CornerRadiusF32 { +impl core::ops::Div for CornerRadiusF32 { type Output = Self; #[inline] fn div(self, rhs: f32) -> Self { @@ -198,7 +198,7 @@ impl std::ops::Div for CornerRadiusF32 { } } -impl std::ops::DivAssign for CornerRadiusF32 { +impl core::ops::DivAssign for CornerRadiusF32 { #[inline] fn div_assign(&mut self, rhs: f32) { *self = Self { @@ -210,7 +210,7 @@ impl std::ops::DivAssign for CornerRadiusF32 { } } -impl std::ops::Mul for CornerRadiusF32 { +impl core::ops::Mul for CornerRadiusF32 { type Output = Self; #[inline] fn mul(self, rhs: f32) -> Self { @@ -223,7 +223,7 @@ impl std::ops::Mul for CornerRadiusF32 { } } -impl std::ops::MulAssign for CornerRadiusF32 { +impl core::ops::MulAssign for CornerRadiusF32 { #[inline] fn mul_assign(&mut self, rhs: f32) { *self = Self { diff --git a/crates/epaint/src/image.rs b/crates/epaint/src/image.rs index 6fbd2b38f..92890e180 100644 --- a/crates/epaint/src/image.rs +++ b/crates/epaint/src/image.rs @@ -301,7 +301,7 @@ impl ColorImage { } } -impl std::ops::Index<(usize, usize)> for ColorImage { +impl core::ops::Index<(usize, usize)> for ColorImage { type Output = Color32; #[inline] @@ -312,7 +312,7 @@ impl std::ops::Index<(usize, usize)> for ColorImage { } } -impl std::ops::IndexMut<(usize, usize)> for ColorImage { +impl core::ops::IndexMut<(usize, usize)> for ColorImage { #[inline] fn index_mut(&mut self, (x, y): (usize, usize)) -> &mut Color32 { let [w, h] = self.size; @@ -335,8 +335,8 @@ impl From> for ImageData { } } -impl std::fmt::Debug for ColorImage { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for ColorImage { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("ColorImage") .field("size", &self.size) .field("pixel-count", &self.pixels.len()) diff --git a/crates/epaint/src/margin.rs b/crates/epaint/src/margin.rs index 0e2063efe..765208ef1 100644 --- a/crates/epaint/src/margin.rs +++ b/crates/epaint/src/margin.rs @@ -120,7 +120,7 @@ impl From for Margin { } /// `Margin + Margin` -impl std::ops::Add for Margin { +impl core::ops::Add for Margin { type Output = Self; #[inline] @@ -135,7 +135,7 @@ impl std::ops::Add for Margin { } /// `Margin + i8` -impl std::ops::Add for Margin { +impl core::ops::Add for Margin { type Output = Self; #[inline] @@ -150,7 +150,7 @@ impl std::ops::Add for Margin { } /// `Margin += i8` -impl std::ops::AddAssign for Margin { +impl core::ops::AddAssign for Margin { #[inline] fn add_assign(&mut self, v: i8) { *self = *self + v; @@ -158,7 +158,7 @@ impl std::ops::AddAssign for Margin { } /// `Margin * f32` -impl std::ops::Mul for Margin { +impl core::ops::Mul for Margin { type Output = Self; #[inline] @@ -173,7 +173,7 @@ impl std::ops::Mul for Margin { } /// `Margin *= f32` -impl std::ops::MulAssign for Margin { +impl core::ops::MulAssign for Margin { #[inline] fn mul_assign(&mut self, v: f32) { *self = *self * v; @@ -181,7 +181,7 @@ impl std::ops::MulAssign for Margin { } /// `Margin / f32` -impl std::ops::Div for Margin { +impl core::ops::Div for Margin { type Output = Self; #[inline] @@ -192,7 +192,7 @@ impl std::ops::Div for Margin { } /// `Margin /= f32` -impl std::ops::DivAssign for Margin { +impl core::ops::DivAssign for Margin { #[inline] fn div_assign(&mut self, v: f32) { *self = *self / v; @@ -200,7 +200,7 @@ impl std::ops::DivAssign for Margin { } /// `Margin - Margin` -impl std::ops::Sub for Margin { +impl core::ops::Sub for Margin { type Output = Self; #[inline] @@ -215,7 +215,7 @@ impl std::ops::Sub for Margin { } /// `Margin - i8` -impl std::ops::Sub for Margin { +impl core::ops::Sub for Margin { type Output = Self; #[inline] @@ -230,7 +230,7 @@ impl std::ops::Sub for Margin { } /// `Margin -= i8` -impl std::ops::SubAssign for Margin { +impl core::ops::SubAssign for Margin { #[inline] fn sub_assign(&mut self, v: i8) { *self = *self - v; @@ -238,7 +238,7 @@ impl std::ops::SubAssign for Margin { } /// `Rect + Margin` -impl std::ops::Add for Rect { +impl core::ops::Add for Rect { type Output = Self; #[inline] @@ -251,7 +251,7 @@ impl std::ops::Add for Rect { } /// `Rect += Margin` -impl std::ops::AddAssign for Rect { +impl core::ops::AddAssign for Rect { #[inline] fn add_assign(&mut self, margin: Margin) { *self = *self + margin; @@ -259,7 +259,7 @@ impl std::ops::AddAssign for Rect { } /// `Rect - Margin` -impl std::ops::Sub for Rect { +impl core::ops::Sub for Rect { type Output = Self; #[inline] @@ -272,7 +272,7 @@ impl std::ops::Sub for Rect { } /// `Rect -= Margin` -impl std::ops::SubAssign for Rect { +impl core::ops::SubAssign for Rect { #[inline] fn sub_assign(&mut self, margin: Margin) { *self = *self - margin; diff --git a/crates/epaint/src/margin_f32.rs b/crates/epaint/src/margin_f32.rs index 2a8c820a1..793e5de47 100644 --- a/crates/epaint/src/margin_f32.rs +++ b/crates/epaint/src/margin_f32.rs @@ -111,7 +111,7 @@ impl From for MarginF32 { } /// `MarginF32 + MarginF32` -impl std::ops::Add for MarginF32 { +impl core::ops::Add for MarginF32 { type Output = Self; #[inline] @@ -126,7 +126,7 @@ impl std::ops::Add for MarginF32 { } /// `MarginF32 + f32` -impl std::ops::Add for MarginF32 { +impl core::ops::Add for MarginF32 { type Output = Self; #[inline] @@ -141,7 +141,7 @@ impl std::ops::Add for MarginF32 { } /// `Margind += f32` -impl std::ops::AddAssign for MarginF32 { +impl core::ops::AddAssign for MarginF32 { #[inline] fn add_assign(&mut self, v: f32) { self.left += v; @@ -152,7 +152,7 @@ impl std::ops::AddAssign for MarginF32 { } /// `MarginF32 * f32` -impl std::ops::Mul for MarginF32 { +impl core::ops::Mul for MarginF32 { type Output = Self; #[inline] @@ -167,7 +167,7 @@ impl std::ops::Mul for MarginF32 { } /// `MarginF32 *= f32` -impl std::ops::MulAssign for MarginF32 { +impl core::ops::MulAssign for MarginF32 { #[inline] fn mul_assign(&mut self, v: f32) { self.left *= v; @@ -178,7 +178,7 @@ impl std::ops::MulAssign for MarginF32 { } /// `MarginF32 / f32` -impl std::ops::Div for MarginF32 { +impl core::ops::Div for MarginF32 { type Output = Self; #[inline] @@ -193,7 +193,7 @@ impl std::ops::Div for MarginF32 { } /// `MarginF32 /= f32` -impl std::ops::DivAssign for MarginF32 { +impl core::ops::DivAssign for MarginF32 { #[inline] fn div_assign(&mut self, v: f32) { self.left /= v; @@ -204,7 +204,7 @@ impl std::ops::DivAssign for MarginF32 { } /// `MarginF32 - MarginF32` -impl std::ops::Sub for MarginF32 { +impl core::ops::Sub for MarginF32 { type Output = Self; #[inline] @@ -219,7 +219,7 @@ impl std::ops::Sub for MarginF32 { } /// `MarginF32 - f32` -impl std::ops::Sub for MarginF32 { +impl core::ops::Sub for MarginF32 { type Output = Self; #[inline] @@ -234,7 +234,7 @@ impl std::ops::Sub for MarginF32 { } /// `MarginF32 -= f32` -impl std::ops::SubAssign for MarginF32 { +impl core::ops::SubAssign for MarginF32 { #[inline] fn sub_assign(&mut self, v: f32) { self.left -= v; @@ -245,7 +245,7 @@ impl std::ops::SubAssign for MarginF32 { } /// `Rect + MarginF32` -impl std::ops::Add for Rect { +impl core::ops::Add for Rect { type Output = Self; #[inline] @@ -258,7 +258,7 @@ impl std::ops::Add for Rect { } /// `Rect += MarginF32` -impl std::ops::AddAssign for Rect { +impl core::ops::AddAssign for Rect { #[inline] fn add_assign(&mut self, margin: MarginF32) { *self = *self + margin; @@ -266,7 +266,7 @@ impl std::ops::AddAssign for Rect { } /// `Rect - MarginF32` -impl std::ops::Sub for Rect { +impl core::ops::Sub for Rect { type Output = Self; #[inline] @@ -279,7 +279,7 @@ impl std::ops::Sub for Rect { } /// `Rect -= MarginF32` -impl std::ops::SubAssign for Rect { +impl core::ops::SubAssign for Rect { #[inline] fn sub_assign(&mut self, margin: MarginF32) { *self = *self - margin; diff --git a/crates/epaint/src/mesh.rs b/crates/epaint/src/mesh.rs index d48c98bc2..5ef978ff3 100644 --- a/crates/epaint/src/mesh.rs +++ b/crates/epaint/src/mesh.rs @@ -90,9 +90,9 @@ impl Mesh { /// Returns the amount of memory used by the vertices and indices. pub fn bytes_used(&self) -> usize { - std::mem::size_of::() - + self.vertices.len() * std::mem::size_of::() - + self.indices.len() * std::mem::size_of::() + core::mem::size_of::() + + self.vertices.len() * core::mem::size_of::() + + self.indices.len() * core::mem::size_of::() } /// Are all indices within the bounds of the contained vertices? diff --git a/crates/epaint/src/mutex.rs b/crates/epaint/src/mutex.rs index 272046823..09e64d30c 100644 --- a/crates/epaint/src/mutex.rs +++ b/crates/epaint/src/mutex.rs @@ -2,7 +2,7 @@ // ---------------------------------------------------------------------------- -const DEADLOCK_DURATION: std::time::Duration = std::time::Duration::from_secs(10); +const DEADLOCK_DURATION: core::time::Duration = core::time::Duration::from_secs(10); /// Provides interior mutability. /// @@ -128,7 +128,7 @@ mod tests { #![expect(clippy::disallowed_methods)] // Ok for tests use crate::mutex::Mutex; - use std::time::Duration; + use core::time::Duration; #[test] fn lock_two_different_mutexes_single_thread() { @@ -161,7 +161,7 @@ mod tests_rwlock { #![expect(clippy::disallowed_methods)] // Ok for tests use crate::mutex::RwLock; - use std::time::Duration; + use core::time::Duration; #[test] fn lock_two_different_rwlocks_single_thread() { diff --git a/crates/epaint/src/shadow.rs b/crates/epaint/src/shadow.rs index ace5ab90a..251b57b7a 100644 --- a/crates/epaint/src/shadow.rs +++ b/crates/epaint/src/shadow.rs @@ -29,7 +29,7 @@ pub struct Shadow { #[test] fn shadow_size() { assert_eq!( - std::mem::size_of::(), + core::mem::size_of::(), 8, "Shadow changed size! If it shrank - good! Update this test. If it grew - bad! Try to find a way to avoid it." ); diff --git a/crates/epaint/src/shapes/bezier_shape.rs b/crates/epaint/src/shapes/bezier_shape.rs index b8c78f273..caf1094a1 100644 --- a/crates/epaint/src/shapes/bezier_shape.rs +++ b/crates/epaint/src/shapes/bezier_shape.rs @@ -1,6 +1,6 @@ #![expect(clippy::many_single_char_names)] -use std::ops::Range; +use core::ops::Range; use crate::{Color32, PathShape, PathStroke, Shape}; use emath::{Pos2, Rect, RectTransform, fast_midpoint}; @@ -256,8 +256,8 @@ impl CubicBezierShape { let theta = (-q / (2.0 * r)).acos() / 3.0; let t1 = 2.0 * r.cbrt() * theta.cos() + h; - let t2 = 2.0 * r.cbrt() * (theta + 120.0 * std::f32::consts::PI / 180.0).cos() + h; - let t3 = 2.0 * r.cbrt() * (theta + 240.0 * std::f32::consts::PI / 180.0).cos() + h; + let t2 = 2.0 * r.cbrt() * (theta + 120.0 * core::f32::consts::PI / 180.0).cos() + h; + let t3 = 2.0 * r.cbrt() * (theta + 240.0 * core::f32::consts::PI / 180.0).cos() + h; if t1 > epsilon && t1 < 1.0 - epsilon { return Some(t1); diff --git a/crates/epaint/src/shapes/paint_callback.rs b/crates/epaint/src/shapes/paint_callback.rs index 00882f0f2..a45109280 100644 --- a/crates/epaint/src/shapes/paint_callback.rs +++ b/crates/epaint/src/shapes/paint_callback.rs @@ -1,4 +1,5 @@ -use std::{any::Any, sync::Arc}; +use core::any::Any; +use std::sync::Arc; use crate::*; @@ -32,7 +33,7 @@ fn test_viewport_rounding() { let left = Rect::from_min_max(pos2(0.0, 0.0), pos2(100.0, 100.0)).with_max_x(x); let right = Rect::from_min_max(pos2(0.0, 0.0), pos2(100.0, 100.0)).with_min_x(x); - for pixels_per_point in [0.618, 1.0, std::f32::consts::PI] { + for pixels_per_point in [0.618, 1.0, core::f32::consts::PI] { let left = ViewportInPixels::from_points(&left, pixels_per_point, [100, 100]); let right = ViewportInPixels::from_points(&right, pixels_per_point, [100, 100]); assert_eq!(left.left_px + left.width_px, right.left_px); @@ -81,15 +82,15 @@ pub struct PaintCallback { pub callback: Arc, } -impl std::fmt::Debug for PaintCallback { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for PaintCallback { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("CustomShape") .field("rect", &self.rect) .finish_non_exhaustive() } } -impl std::cmp::PartialEq for PaintCallback { +impl core::cmp::PartialEq for PaintCallback { fn eq(&self, other: &Self) -> bool { self.rect.eq(&other.rect) && Arc::ptr_eq(&self.callback, &other.callback) } diff --git a/crates/epaint/src/shapes/rect_shape.rs b/crates/epaint/src/shapes/rect_shape.rs index e0c528377..159d56af5 100644 --- a/crates/epaint/src/shapes/rect_shape.rs +++ b/crates/epaint/src/shapes/rect_shape.rs @@ -62,12 +62,12 @@ pub struct RectShape { #[test] fn rect_shape_size() { assert_eq!( - std::mem::size_of::(), + core::mem::size_of::(), 56, "RectShape changed size! If it shrank - good! Update this test. If it grew - bad! Try to find a way to avoid it." ); assert!( - std::mem::size_of::() <= 64, + core::mem::size_of::() <= 64, "RectShape is getting way too big!" ); } diff --git a/crates/epaint/src/shapes/shape.rs b/crates/epaint/src/shapes/shape.rs index ff15708f1..55be52ba5 100644 --- a/crates/epaint/src/shapes/shape.rs +++ b/crates/epaint/src/shapes/shape.rs @@ -73,12 +73,12 @@ pub enum Shape { #[test] fn shape_size() { assert_eq!( - std::mem::size_of::(), + core::mem::size_of::(), 64, "Shape changed size! If it shrank - good! Update this test. If it grew - bad! Try to find a way to avoid it." ); assert!( - std::mem::size_of::() <= 64, + core::mem::size_of::() <= 64, "Shape is getting way too big!" ); } diff --git a/crates/epaint/src/shapes/text_shape.rs b/crates/epaint/src/shapes/text_shape.rs index 3e177db07..8083dcf25 100644 --- a/crates/epaint/src/shapes/text_shape.rs +++ b/crates/epaint/src/shapes/text_shape.rs @@ -201,7 +201,7 @@ mod tests { // 90 degree rotation if let Shape::Text(ts) = &mut t { - ts.angle = std::f32::consts::PI / 2.0; + ts.angle = core::f32::consts::PI / 2.0; } let size_rot = t.visual_bounding_rect().size(); diff --git a/crates/epaint/src/stats.rs b/crates/epaint/src/stats.rs index de8f275cf..8c191dcb1 100644 --- a/crates/epaint/src/stats.rs +++ b/crates/epaint/src/stats.rs @@ -26,7 +26,7 @@ impl From<&[T]> for AllocInfo { } } -impl std::ops::Add for AllocInfo { +impl core::ops::Add for AllocInfo { type Output = Self; fn add(self, rhs: Self) -> Self { @@ -47,13 +47,13 @@ impl std::ops::Add for AllocInfo { } } -impl std::ops::AddAssign for AllocInfo { +impl core::ops::AddAssign for AllocInfo { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; } } -impl std::iter::Sum for AllocInfo { +impl core::iter::Sum for AllocInfo { fn sum(iter: I) -> Self where I: Iterator, @@ -95,13 +95,13 @@ impl AllocInfo { } pub fn from_slice(slice: &[T]) -> Self { - use std::mem::size_of; + use core::mem::size_of; let element_size = size_of::(); Self { element_size: ElementSize::Homogeneous(element_size), num_allocs: 1, num_elements: slice.len(), - num_bytes: std::mem::size_of_val(slice), + num_bytes: core::mem::size_of_val(slice), } } diff --git a/crates/epaint/src/stroke.rs b/crates/epaint/src/stroke.rs index 1b072e4bf..1a5b2f0d1 100644 --- a/crates/epaint/src/stroke.rs +++ b/crates/epaint/src/stroke.rs @@ -1,4 +1,5 @@ -use std::{fmt::Debug, sync::Arc}; +use core::fmt::Debug; +use std::sync::Arc; use emath::GuiRounding as _; @@ -86,9 +87,9 @@ where } } -impl std::hash::Hash for Stroke { +impl core::hash::Hash for Stroke { #[inline(always)] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { let Self { width, color } = *self; emath::OrderedFloat(width).hash(state); color.hash(state); diff --git a/crates/epaint/src/tessellator.rs b/crates/epaint/src/tessellator.rs index 716fe5424..7b207abeb 100644 --- a/crates/epaint/src/tessellator.rs +++ b/crates/epaint/src/tessellator.rs @@ -1579,7 +1579,7 @@ impl Tessellator { let eased = 2.0 * (percent - percent.powf(2.0)) * ratio + percent.powf(2.0); // Scale the ease to the quarter - let t = eased * std::f32::consts::FRAC_PI_2; + let t = eased * core::f32::consts::FRAC_PI_2; Vec2::new(radius.x * f32::cos(t), radius.y * f32::sin(t)) }) .collect(); diff --git a/crates/epaint/src/text/cursor.rs b/crates/epaint/src/text/cursor.rs index ac2e4216d..1143fc59f 100644 --- a/crates/epaint/src/text/cursor.rs +++ b/crates/epaint/src/text/cursor.rs @@ -37,7 +37,7 @@ impl PartialEq for CCursor { } } -impl std::ops::Add for CCursor { +impl core::ops::Add for CCursor { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -48,7 +48,7 @@ impl std::ops::Add for CCursor { } } -impl std::ops::Add for CCursor { +impl core::ops::Add for CCursor { type Output = Self; fn add(self, rhs: CharIndex) -> Self::Output { @@ -59,7 +59,7 @@ impl std::ops::Add for CCursor { } } -impl std::ops::Sub for CCursor { +impl core::ops::Sub for CCursor { type Output = Self; fn sub(self, rhs: usize) -> Self::Output { @@ -70,7 +70,7 @@ impl std::ops::Sub for CCursor { } } -impl std::ops::Sub for CCursor { +impl core::ops::Sub for CCursor { type Output = Self; fn sub(self, rhs: CharIndex) -> Self::Output { @@ -81,13 +81,13 @@ impl std::ops::Sub for CCursor { } } -impl std::ops::AddAssign for CCursor { +impl core::ops::AddAssign for CCursor { fn add_assign(&mut self, rhs: usize) { self.index = self.index.saturating_add(rhs); } } -impl std::ops::SubAssign for CCursor { +impl core::ops::SubAssign for CCursor { fn sub_assign(&mut self, rhs: usize) { self.index = self.index.saturating_sub(rhs); } diff --git a/crates/epaint/src/text/font.rs b/crates/epaint/src/text/font.rs index 12885596e..287230db3 100644 --- a/crates/epaint/src/text/font.rs +++ b/crates/epaint/src/text/font.rs @@ -382,7 +382,7 @@ impl FontFace { font_data: Blob, index: u32, tweak: FontTweak, - ) -> Result> { + ) -> Result> { let font = FontCell::try_new(font_data, |font_data| { let skrifa_font = skrifa::FontRef::from_index(AsRef::<[u8]>::as_ref(font_data.as_ref()), index)?; @@ -414,7 +414,7 @@ impl FontFace { }) .flatten(); - Ok::, Box>(DependentFontData { + Ok::, Box>(DependentFontData { skrifa: skrifa_font, charmap, outline_glyphs: glyphs, @@ -574,7 +574,7 @@ impl FontFace { let axes = font_data.skrifa.axes(); // Override the default coordinates with ones specified via FontTweak, then the ones specified directly via the // argument (probably from TextFormat). - let settings = std::iter::chain(self.tweak.coords.as_ref(), coords.as_ref()); + let settings = core::iter::chain(self.tweak.coords.as_ref(), coords.as_ref()); let location = axes.location(settings); let location_hash = LocationHash::new(&location); diff --git a/crates/epaint/src/text/fonts.rs b/crates/epaint/src/text/fonts.rs index 62b1b83a0..28ab8bbf5 100644 --- a/crates/epaint/src/text/fonts.rs +++ b/crates/epaint/src/text/fonts.rs @@ -1,11 +1,5 @@ -use std::{ - borrow::Cow, - collections::BTreeMap, - sync::{ - Arc, - atomic::{AtomicUsize, Ordering}, - }, -}; +use core::sync::atomic::{AtomicUsize, Ordering}; +use std::{borrow::Cow, collections::BTreeMap, sync::Arc}; use crate::{ TextureAtlas, @@ -60,9 +54,9 @@ impl FontId { } } -impl std::hash::Hash for FontId { +impl core::hash::Hash for FontId { #[inline(always)] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { let Self { size, family } = self; emath::OrderedFloat(*size).hash(state); family.hash(state); @@ -100,8 +94,8 @@ pub enum FontFamily { Name(Arc), } -impl std::fmt::Display for FontFamily { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for FontFamily { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Monospace => "Monospace".fmt(f), Self::Proportional => "Proportional".fmt(f), diff --git a/crates/epaint/src/text/index.rs b/crates/epaint/src/text/index.rs index 3fcd9a4ce..0f1450740 100644 --- a/crates/epaint/src/text/index.rs +++ b/crates/epaint/src/text/index.rs @@ -4,7 +4,7 @@ //! (Unicode scalar) offset. Mixing the two is a common source of bugs, //! so we use distinct types to keep them apart. -use std::ops::Range; +use core::ops::Range; /// A byte offset into a UTF-8 string. /// @@ -63,7 +63,7 @@ macro_rules! impl_text_index { } } - impl std::ops::Add for $Type { + impl core::ops::Add for $Type { type Output = Self; #[inline] @@ -73,7 +73,7 @@ macro_rules! impl_text_index { } /// Compose offsets, e.g. a base position plus a relative one. - impl std::ops::Add<$Type> for $Type { + impl core::ops::Add<$Type> for $Type { type Output = Self; #[inline] @@ -82,7 +82,7 @@ macro_rules! impl_text_index { } } - impl std::ops::Sub for $Type { + impl core::ops::Sub for $Type { type Output = Self; #[inline] @@ -91,7 +91,7 @@ macro_rules! impl_text_index { } } - impl std::ops::Sub<$Type> for $Type { + impl core::ops::Sub<$Type> for $Type { type Output = Self; #[inline] @@ -100,30 +100,30 @@ macro_rules! impl_text_index { } } - impl std::ops::AddAssign for $Type { + impl core::ops::AddAssign for $Type { #[inline] fn add_assign(&mut self, rhs: usize) { self.0 += rhs; } } - impl std::ops::AddAssign<$Type> for $Type { + impl core::ops::AddAssign<$Type> for $Type { #[inline] fn add_assign(&mut self, rhs: Self) { self.0 += rhs.0; } } - impl std::ops::SubAssign for $Type { + impl core::ops::SubAssign for $Type { #[inline] fn sub_assign(&mut self, rhs: usize) { self.0 -= rhs; } } - impl std::fmt::Display for $Type { + impl core::fmt::Display for $Type { #[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) } } diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 442f1f86c..06ddc3b1f 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -1,7 +1,7 @@ #![expect(clippy::unwrap_used)] // TODO(emilk): remove unwraps +use core::{iter, ops::Range}; use std::sync::Arc; -use std::{iter, ops::Range}; use emath::{Align, GuiRounding as _, NumExt as _, Pos2, Rect, Vec2, pos2, vec2}; @@ -523,7 +523,7 @@ fn layout_section( /// Iterator that either splits on `'\n'` or yields the whole string once. /// Avoids `Box` and `Vec<&str>` allocation. enum SplitOrWhole<'a> { - Split(std::str::Split<'a, char>), + Split(core::str::Split<'a, char>), Whole(iter::Once<&'a str>), } @@ -571,7 +571,7 @@ fn calculate_intrinsic_size( .glyphs .iter() .map(|g| g.line_height) - .max_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)) + .max_by(|a, b| a.partial_cmp(b).unwrap_or(core::cmp::Ordering::Equal)) .unwrap_or(paragraph.empty_paragraph_height); if idx == 0 { height = f32::max(height, job.first_row_min_height); @@ -1437,7 +1437,7 @@ fn shape_text( #[cfg(test)] mod tests { - use std::iter; + use core::iter; use super::{super::*, *}; use crate::text::cursor::CCursor; diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 97af735b4..e51c0e1cd 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -1,5 +1,5 @@ +use core::{ops::Range, str::FromStr as _}; use std::sync::Arc; -use std::{ops::Range, str::FromStr as _}; use super::{ cursor::{CCursor, LayoutCursor}, @@ -271,7 +271,7 @@ impl LayoutJob { let Range { start, end } = section.byte_range; assert!(start <= end, "LayoutSection has a reversed byte_range"); } - for (prev, next) in std::iter::zip(&self.sections, self.sections.iter().skip(1)) { + for (prev, next) in core::iter::zip(&self.sections, self.sections.iter().skip(1)) { assert_eq!( prev.byte_range.end, next.byte_range.start, "LayoutSections must be ordered with no gaps and no overlaps" @@ -304,9 +304,9 @@ impl LayoutJob { } } -impl std::hash::Hash for LayoutJob { +impl core::hash::Hash for LayoutJob { #[inline] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { let Self { text, sections, @@ -355,9 +355,9 @@ pub struct LayoutSection { pub format: TextFormat, } -impl std::hash::Hash for LayoutSection { +impl core::hash::Hash for LayoutSection { #[inline] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { let Self { leading_space, byte_range, @@ -462,8 +462,8 @@ impl AsMut<[(font_types::Tag, f32)]> for VariationCoords { } } -impl std::hash::Hash for VariationCoords { - fn hash(&self, state: &mut H) { +impl core::hash::Hash for VariationCoords { + fn hash(&self, state: &mut H) { self.0.len().hash(state); for (tag, coord) in &self.0 { tag.hash(state); @@ -541,9 +541,9 @@ impl Default for TextFormat { } } -impl std::hash::Hash for TextFormat { +impl core::hash::Hash for TextFormat { #[inline] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { let Self { font_id, extra_letter_spacing, @@ -651,9 +651,9 @@ pub struct TextWrapping { pub overflow_character: Option, } -impl std::hash::Hash for TextWrapping { +impl core::hash::Hash for TextWrapping { #[inline] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { let Self { max_width, max_rows, @@ -817,7 +817,7 @@ impl PlacedRow { } } -impl std::ops::Deref for PlacedRow { +impl core::ops::Deref for PlacedRow { type Target = Row; fn deref(&self) -> &Self::Target { @@ -1126,14 +1126,14 @@ impl AsRef for Galley { } } -impl std::borrow::Borrow for Galley { +impl core::borrow::Borrow for Galley { #[inline] fn borrow(&self) -> &str { self.text() } } -impl std::ops::Deref for Galley { +impl core::ops::Deref for Galley { type Target = str; #[inline] fn deref(&self) -> &str { diff --git a/crates/epaint/src/texture_atlas.rs b/crates/epaint/src/texture_atlas.rs index 4f8548817..0bb235b33 100644 --- a/crates/epaint/src/texture_atlas.rs +++ b/crates/epaint/src/texture_atlas.rs @@ -202,7 +202,7 @@ impl TextureAtlas { pub fn take_delta(&mut self) -> Option { let texture_options = Self::texture_options(); - let dirty = std::mem::replace(&mut self.dirty, Rectu::NOTHING); + let dirty = core::mem::replace(&mut self.dirty, Rectu::NOTHING); if dirty == Rectu::NOTHING { None } else if dirty == Rectu::EVERYTHING { diff --git a/crates/epaint/src/texture_handle.rs b/crates/epaint/src/texture_handle.rs index bbbf490b5..b8b4310dc 100644 --- a/crates/epaint/src/texture_handle.rs +++ b/crates/epaint/src/texture_handle.rs @@ -47,9 +47,9 @@ impl PartialEq for TextureHandle { impl Eq for TextureHandle {} -impl std::hash::Hash for TextureHandle { +impl core::hash::Hash for TextureHandle { #[inline] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { self.id.hash(state); } } diff --git a/crates/epaint/src/textures.rs b/crates/epaint/src/textures.rs index 1c4104a6e..594cada75 100644 --- a/crates/epaint/src/textures.rs +++ b/crates/epaint/src/textures.rs @@ -1,7 +1,7 @@ use crate::{ImageData, ImageDelta, TextureId}; use ahash::{HashMap, HashSet}; +use core::mem; use smallvec::{SmallVec, smallvec}; -use std::mem; // ---------------------------------------------------------------------------- @@ -100,7 +100,7 @@ impl TextureManager { /// /// These should be applied to the painting subsystem each frame. pub fn take_delta(&mut self) -> TexturesDelta { - std::mem::take(&mut self.delta) + core::mem::take(&mut self.delta) } /// Get meta-data about a specific texture. @@ -343,9 +343,9 @@ impl Drop for TexturesDelta { } } -impl std::fmt::Debug for TexturesDelta { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use std::fmt::Write as _; +impl core::fmt::Debug for TexturesDelta { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + use core::fmt::Write as _; let mut debug_struct = f.debug_struct("TexturesDelta"); if !self.set.is_empty() { diff --git a/crates/epaint/src/util/mod.rs b/crates/epaint/src/util/mod.rs index 471576630..ad324adcf 100644 --- a/crates/epaint/src/util/mod.rs +++ b/crates/epaint/src/util/mod.rs @@ -1,12 +1,12 @@ /// Hash the given value with a predictable hasher. #[inline] -pub fn hash(value: impl std::hash::Hash) -> u64 { +pub fn hash(value: impl core::hash::Hash) -> u64 { ahash::RandomState::with_seeds(1, 2, 3, 4).hash_one(value) } /// Hash the given value with the given hasher. #[inline] -pub fn hash_with(value: impl std::hash::Hash, mut hasher: impl std::hash::Hasher) -> u64 { +pub fn hash_with(value: impl core::hash::Hash, mut hasher: impl core::hash::Hasher) -> u64 { value.hash(&mut hasher); hasher.finish() } diff --git a/examples/external_eventloop/src/main.rs b/examples/external_eventloop/src/main.rs index 227fd3f33..a84dcd551 100644 --- a/examples/external_eventloop/src/main.rs +++ b/examples/external_eventloop/src/main.rs @@ -1,8 +1,9 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![expect(rustdoc::missing_crate_level_docs, clippy::unwrap_used)] // it's an example +use core::cell::Cell; use eframe::{UserEvent, egui}; -use std::{cell::Cell, rc::Rc}; +use std::rc::Rc; use winit::event_loop::{ControlFlow, EventLoop}; fn main() -> eframe::Result { diff --git a/examples/external_eventloop_async/src/app.rs b/examples/external_eventloop_async/src/app.rs index d0e62e3cc..ea9c0b413 100644 --- a/examples/external_eventloop_async/src/app.rs +++ b/examples/external_eventloop_async/src/app.rs @@ -1,6 +1,7 @@ #![expect(clippy::unwrap_used)] // It's an example -use std::{cell::Cell, io, os::fd::AsRawFd as _, rc::Rc, time::Duration}; +use core::{cell::Cell, time::Duration}; +use std::{io, os::fd::AsRawFd as _, rc::Rc}; use tokio::task::LocalSet; use winit::event_loop::{ControlFlow, EventLoop}; diff --git a/examples/file_dialog/src/main.rs b/examples/file_dialog/src/main.rs index d42da9b82..3034e2376 100644 --- a/examples/file_dialog/src/main.rs +++ b/examples/file_dialog/src/main.rs @@ -83,8 +83,8 @@ impl eframe::App for MyApp { /// Preview hovering files: fn preview_files_being_dropped(ctx: &egui::Context) { + use core::fmt::Write as _; use egui::{Align2, Color32, Id, LayerId, Order, TextStyle}; - use std::fmt::Write as _; if !ctx.input(|i| i.raw.hovered_files.is_empty()) { let text = ctx.input(|i| { diff --git a/examples/hello_world_par/src/main.rs b/examples/hello_world_par/src/main.rs index b064c65bd..ee62b1668 100644 --- a/examples/hello_world_par/src/main.rs +++ b/examples/hello_world_par/src/main.rs @@ -106,10 +106,10 @@ impl MyApp { } } -impl std::ops::Drop for MyApp { +impl core::ops::Drop for MyApp { fn drop(&mut self) { for (handle, show_tx) in self.threads.drain(..) { - std::mem::drop(show_tx); + core::mem::drop(show_tx); handle.join().unwrap(); } } diff --git a/examples/multiple_viewports/src/main.rs b/examples/multiple_viewports/src/main.rs index b75d3c016..59383aa93 100644 --- a/examples/multiple_viewports/src/main.rs +++ b/examples/multiple_viewports/src/main.rs @@ -1,10 +1,8 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![expect(rustdoc::missing_crate_level_docs)] // it's an example -use std::sync::{ - Arc, - atomic::{AtomicBool, Ordering}, -}; +use core::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; use eframe::egui; diff --git a/examples/puffin_profiler/src/main.rs b/examples/puffin_profiler/src/main.rs index 89118e8c7..03e4eb790 100644 --- a/examples/puffin_profiler/src/main.rs +++ b/examples/puffin_profiler/src/main.rs @@ -1,10 +1,8 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![expect(rustdoc::missing_crate_level_docs)] // it's an example -use std::sync::{ - Arc, - atomic::{AtomicBool, Ordering}, -}; +use core::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; use eframe::egui; @@ -88,7 +86,7 @@ impl eframe::App for MyApp { .clicked() { puffin::profile_scope!("long_sleep"); - std::thread::sleep(std::time::Duration::from_millis(50)); + std::thread::sleep(core::time::Duration::from_millis(50)); } ui.checkbox( @@ -172,7 +170,7 @@ fn start_puffin_server() { // We can store the server if we want, but in this case we just want // it to keep running. Dropping it closes the server, so let's not drop it! #[expect(clippy::mem_forget)] - std::mem::forget(puffin_server); + core::mem::forget(puffin_server); } Err(err) => { log::error!("Failed to start puffin server: {err}"); diff --git a/examples/serial_windows/src/main.rs b/examples/serial_windows/src/main.rs index 8ef07dc9c..0ece04d34 100644 --- a/examples/serial_windows/src/main.rs +++ b/examples/serial_windows/src/main.rs @@ -19,7 +19,7 @@ fn main() -> eframe::Result { Box::new(|_cc| Ok(Box::new(MyApp { has_next: true }))), )?; - std::thread::sleep(std::time::Duration::from_secs(2)); + std::thread::sleep(core::time::Duration::from_secs(2)); log::info!("Starting second window…"); eframe::run_native( @@ -28,7 +28,7 @@ fn main() -> eframe::Result { Box::new(|_cc| Ok(Box::new(MyApp { has_next: true }))), )?; - std::thread::sleep(std::time::Duration::from_secs(2)); + std::thread::sleep(core::time::Duration::from_secs(2)); log::info!("Starting third window…"); eframe::run_native( diff --git a/examples/user_attention/src/main.rs b/examples/user_attention/src/main.rs index 46d8fbb99..6b16ddd07 100644 --- a/examples/user_attention/src/main.rs +++ b/examples/user_attention/src/main.rs @@ -4,7 +4,8 @@ use eframe::{CreationContext, NativeOptions, egui}; use egui::{Button, CentralPanel, UserAttentionType}; -use std::time::{Duration, SystemTime}; +use core::time::Duration; +use std::time::SystemTime; fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). diff --git a/tests/egui_tests/tests/regression_tests.rs b/tests/egui_tests/tests/regression_tests.rs index 1a65254a7..b72ac6b61 100644 --- a/tests/egui_tests/tests/regression_tests.rs +++ b/tests/egui_tests/tests/regression_tests.rs @@ -316,7 +316,7 @@ fn warn_if_rect_changes_id() { #[test] #[cfg(debug_assertions)] fn warn_if_rect_changes_id_false_positive_parent_shift() { - use std::cell::Cell; + use core::cell::Cell; let counter = Cell::new(0); let button_rect = egui::Rect::from_min_size(egui::pos2(10.0, 10.0), egui::vec2(100.0, 30.0)); diff --git a/tests/egui_tests/tests/test_atoms.rs b/tests/egui_tests/tests/test_atoms.rs index 48babfbd7..6368de3a8 100644 --- a/tests/egui_tests/tests/test_atoms.rs +++ b/tests/egui_tests/tests/test_atoms.rs @@ -220,8 +220,8 @@ fn test_atom_selectable_senses_click_and_drag() { /// See . #[test] fn test_atom_selectable_text_can_be_copied() { + use core::cell::Cell; use egui::{AtomLayout, Event, Modifiers, OutputCommand, PointerButton, Pos2, Rect}; - use std::cell::Cell; fn copied_text(selectable: bool) -> Option { let rect_cell = Cell::new(Rect::NOTHING); diff --git a/tests/egui_tests/tests/test_panel_drag.rs b/tests/egui_tests/tests/test_panel_drag.rs index 0909753cc..96c7daba1 100644 --- a/tests/egui_tests/tests/test_panel_drag.rs +++ b/tests/egui_tests/tests/test_panel_drag.rs @@ -381,7 +381,7 @@ fn switched_bottom_panel_harness(start_expanded: bool) -> Harness<'static, Switc } /// Assert that the panel edge crossed `gap` gradually, rather than in one frame. -fn assert_crossed_gradually(tops: &[f32], gap: std::ops::Range) { +fn assert_crossed_gradually(tops: &[f32], gap: core::ops::Range) { let frames_in_gap = tops.iter().filter(|top| gap.contains(top)).count(); assert!( 3 <= frames_in_gap, diff --git a/tests/test_background_logic/src/main.rs b/tests/test_background_logic/src/main.rs index b1c559916..0709bc2ed 100644 --- a/tests/test_background_logic/src/main.rs +++ b/tests/test_background_logic/src/main.rs @@ -2,7 +2,7 @@ #![expect(rustdoc::missing_crate_level_docs)] #![allow(clippy::print_stderr)] -use std::time::Duration; +use core::time::Duration; use eframe::egui::{self, ViewportInfo}; @@ -56,7 +56,7 @@ fn viewport_info(ctx: &egui::Context) -> String { ]; for (name, value) in flags { if let Some(value) = value { - use std::fmt::Write as _; + use core::fmt::Write as _; write!(s, " {name}={value}").ok(); } } diff --git a/tests/test_inline_glow_paint/src/main.rs b/tests/test_inline_glow_paint/src/main.rs index d23288706..517d1706d 100644 --- a/tests/test_inline_glow_paint/src/main.rs +++ b/tests/test_inline_glow_paint/src/main.rs @@ -11,7 +11,7 @@ use eframe::egui; use eframe::glow; -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { renderer: eframe::Renderer::Glow, diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 81471d622..fb2bf2570 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -6,7 +6,7 @@ mod deny; pub(crate) mod utils; -type DynError = Box; +type DynError = Box; fn main() { if let Err(e) = try_main() {