From b3c46bf52d459b8ff86aca5e0ca7ca104f443a61 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Fri, 13 Feb 2026 11:13:37 +0100 Subject: [PATCH] all: replace debug_fn with fmt::from_fn --- src/cli/idle.rs | 6 ++--- src/cli/randr.rs | 8 +++---- src/cmm/cmm_transform.rs | 5 ++-- src/config/handler.rs | 4 ++-- src/ei/ei_client.rs | 5 ++-- src/format.rs | 8 ++++--- src/ifs/wl_seat/text_input/simple_im.rs | 6 ++--- src/pipewire/pw_pod/pw_debug.rs | 31 ++++++++++++++----------- src/tasks/connector.rs | 7 +++--- src/utils.rs | 1 - src/utils/debug_fn.rs | 30 ------------------------ 11 files changed, 41 insertions(+), 70 deletions(-) delete mode 100644 src/utils/debug_fn.rs diff --git a/src/cli/idle.rs b/src/cli/idle.rs index 3fe6443c..9bc190ce 100644 --- a/src/cli/idle.rs +++ b/src/cli/idle.rs @@ -2,11 +2,11 @@ use { crate::{ cli::{GlobalArgs, IdleArgs, duration::parse_duration}, tools::tool_client::{Handle, ToolClient, with_tool_client}, - utils::{debug_fn::debug_fn, stack::Stack}, + utils::stack::Stack, wire::{JayIdleId, WlSurfaceId, jay_compositor, jay_idle}, }, clap::{Args, Subcommand}, - std::{cell::Cell, rc::Rc}, + std::{cell::Cell, fmt, rc::Rc}, }; #[derive(Subcommand, Debug, Default)] @@ -105,7 +105,7 @@ impl Idle { }); tc.round_trip().await; let interval = |iv: u64| { - debug_fn(move |f| { + fmt::from_fn(move |f| { let minutes = iv / 60; let seconds = iv % 60; if minutes == 0 && seconds == 0 { diff --git a/src/cli/randr.rs b/src/cli/randr.rs index 3981b04a..b07ab20e 100644 --- a/src/cli/randr.rs +++ b/src/cli/randr.rs @@ -7,9 +7,7 @@ use { ifs::wl_output::BlendSpace, scale::Scale, tools::tool_client::{Handle, ToolClient, with_tool_client}, - utils::{ - debug_fn::debug_fn, errorfmt::ErrorFmt, ordered_float::F64, transform_ext::TransformExt, - }, + utils::{errorfmt::ErrorFmt, ordered_float::F64, transform_ext::TransformExt}, wire::{JayRandrId, jay_compositor, jay_randr}, }, clap::{ @@ -21,7 +19,7 @@ use { linearize::LinearizeExt, std::{ cell::RefCell, - fmt::{Display, Formatter}, + fmt::{self, Display, Formatter}, rc::Rc, str::FromStr, time::Duration, @@ -1067,7 +1065,7 @@ impl Randr { if let Some(p) = &o.native_gamut { println!( " native gamut:{}", - debug_fn(|f| { + fmt::from_fn(|f| { if o.use_native_gamut { f.write_str(" (used for default color space)")?; } diff --git a/src/cmm/cmm_transform.rs b/src/cmm/cmm_transform.rs index 5b8a8537..2c2816a7 100644 --- a/src/cmm/cmm_transform.rs +++ b/src/cmm/cmm_transform.rs @@ -2,9 +2,10 @@ use { crate::{ cmm::{cmm_eotf::Eotf, cmm_primaries::Primaries}, theme::Color, - utils::{debug_fn::debug_fn, ordered_float::F64}, + utils::ordered_float::F64, }, std::{ + fmt, fmt::{Debug, Formatter}, hash::{Hash, Hasher}, marker::PhantomData, @@ -52,7 +53,7 @@ impl Debug for ColorMatrix { } fn format_matrix<'a>(m: &'a [[F64; 4]; 3]) -> impl Debug + use<'a> { - debug_fn(move |f| { + fmt::from_fn(move |f| { let iter = m .iter() .copied() diff --git a/src/config/handler.rs b/src/config/handler.rs index d32f608b..a7290d80 100644 --- a/src/config/handler.rs +++ b/src/config/handler.rs @@ -35,7 +35,6 @@ use { utils::{ asyncevent::AsyncEvent, copyhashmap::CopyHashMap, - debug_fn::debug_fn, errorfmt::ErrorFmt, numcell::NumCell, oserror::OsError, @@ -83,6 +82,7 @@ use { regex::Regex, std::{ cell::Cell, + fmt, hash::Hash, ops::Deref, rc::{Rc, Weak}, @@ -273,7 +273,7 @@ impl ConfigProxyHandler { LogLevel::Debug => Level::Debug, LogLevel::Trace => Level::Trace, }; - let debug = debug_fn(|fmt| { + let debug = fmt::from_fn(|fmt| { if let Some(file) = file { write!(fmt, "{}", file)?; if let Some(line) = line { diff --git a/src/ei/ei_client.rs b/src/ei/ei_client.rs index 185604d3..c5c1d85c 100644 --- a/src/ei/ei_client.rs +++ b/src/ei/ei_client.rs @@ -16,7 +16,6 @@ use { asyncevent::AsyncEvent, buffd::{EiMsgFormatter, EiMsgParser, EiMsgParserError, OutBufferSwapchain}, clonecell::CloneCell, - debug_fn::debug_fn, errorfmt::ErrorFmt, numcell::NumCell, pid_info::{PidInfo, get_pid_info, get_socket_creds}, @@ -27,7 +26,7 @@ use { std::{ cell::{Cell, RefCell}, error::Error, - fmt::Debug, + fmt::{self, Debug}, mem, ops::DerefMut, rc::Rc, @@ -128,7 +127,7 @@ impl EiClients { log::info!( "Client {} connected{:?}", data.id, - debug_fn(|fmt| { + fmt::from_fn(|fmt| { if let Some(p) = &data.pid_info { write!(fmt, ", pid: {}, uid: {}, comm: {:?}", p.pid, p.uid, p.comm)?; } diff --git a/src/format.rs b/src/format.rs index 300c25ef..9b752cf0 100644 --- a/src/format.rs +++ b/src/format.rs @@ -9,13 +9,15 @@ use { SPA_VIDEO_FORMAT_UNKNOWN, SPA_VIDEO_FORMAT_xBGR_210LE, SPA_VIDEO_FORMAT_xRGB_210LE, SpaVideoFormat, }, - utils::debug_fn::debug_fn, }, ahash::AHashMap, ash::vk, jay_config::video::Format as ConfigFormat, once_cell::sync::Lazy, - std::fmt::{Debug, Write}, + std::{ + fmt, + fmt::{Debug, Write}, + }, }; #[derive(Copy, Clone, Debug)] @@ -134,7 +136,7 @@ const fn fourcc_code(a: char, b: char, c: char, d: char) -> u32 { #[expect(dead_code)] pub fn debug(fourcc: u32) -> impl Debug { - debug_fn(move |fmt| { + fmt::from_fn(move |fmt| { fmt.write_char(fourcc as u8 as char)?; fmt.write_char((fourcc >> 8) as u8 as char)?; fmt.write_char((fourcc >> 16) as u8 as char)?; diff --git a/src/ifs/wl_seat/text_input/simple_im.rs b/src/ifs/wl_seat/text_input/simple_im.rs index 6a3a905b..917e3312 100644 --- a/src/ifs/wl_seat/text_input/simple_im.rs +++ b/src/ifs/wl_seat/text_input/simple_im.rs @@ -11,7 +11,7 @@ use { wl_surface::zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2, }, keyboard::KeyboardState, - utils::{clonecell::CloneCell, debug_fn::debug_fn, smallmap::SmallMap}, + utils::{clonecell::CloneCell, smallmap::SmallMap}, wire::ZwpInputPopupSurfaceV2Id, }, kbvm::{ @@ -24,7 +24,7 @@ use { }, std::{ cell::{Cell, RefCell}, - fmt::Write, + fmt::{self, Write}, rc::Rc, }, }; @@ -154,7 +154,7 @@ impl UnicodeInput { let _ = write!(self.text, "U+{:x}", self.cp); self.cursor = self.text.len() as _; if let Some(char) = char::from_u32(self.cp) { - let s = debug_fn(|f| { + let s = fmt::from_fn(|f| { if char == '\n' { f.write_str("\\n") } else { diff --git a/src/pipewire/pw_pod/pw_debug.rs b/src/pipewire/pw_pod/pw_debug.rs index ddda7fb4..feb98420 100644 --- a/src/pipewire/pw_pod/pw_debug.rs +++ b/src/pipewire/pw_pod/pw_debug.rs @@ -31,9 +31,12 @@ use { SpaVideoTransferFunction, }, }, - utils::{debug_fn::debug_fn, errorfmt::ErrorFmt}, + utils::errorfmt::ErrorFmt, + }, + std::{ + fmt, + fmt::{Debug, DebugList, Formatter, Write}, }, - std::fmt::{Debug, DebugList, Formatter, Write}, }; trait PwPodObjectDebugger: Sync { @@ -62,7 +65,7 @@ where s.field("flags", &value.flags) .field( "pod", - &debug_fn(|f| (self.debug_pod)(value.key, f, value.pod)), + &fmt::from_fn(|f| (self.debug_pod)(value.key, f, value.pod)), ) .finish() } @@ -83,16 +86,16 @@ where .field("flags", &c.flags) .field( "elements", - &debug_fn(|fmt| { + &fmt::from_fn(|fmt| { array_body_debug(fmt, c.elements, |l, p| { match p.read_pod_body_packed(ty, c.elements.child_len) { Ok(p) => { - l.entry(&debug_fn(|fmt| f(fmt, p))); + l.entry(&fmt::from_fn(|fmt| f(fmt, p))); true } Err(e) => { let e = ErrorFmt(e); - l.entry(&debug_fn(|fmt| { + l.entry(&fmt::from_fn(|fmt| { write!(fmt, "Could not read choice element: {}", e) })); false @@ -151,7 +154,7 @@ where } Err(e) => { let e = ErrorFmt(e); - l.entry(&debug_fn(|f| write!(f, "Could not read id: {}", e))); + l.entry(&fmt::from_fn(|f| write!(f, "Could not read id: {}", e))); false } }) @@ -334,18 +337,18 @@ impl<'a> Debug for PwPodObject<'a> { s.field("id", id); s.field( "props", - &debug_fn(|f| { + &fmt::from_fn(|f| { let mut l = f.debug_list(); let mut parser = self.probs; while parser.len() > 0 { match parser.read_prop() { Ok(p) => match debugger { - Some(d) => l.entry(&debug_fn(|fmt| d.debug_property(fmt, p))), + Some(d) => l.entry(&fmt::from_fn(|fmt| d.debug_property(fmt, p))), _ => l.entry(&p), }, Err(e) => { let e = ErrorFmt(e); - l.entry(&debug_fn(|f| { + l.entry(&fmt::from_fn(|f| { write!(f, "Could not read object property: {}", &e) })); break; @@ -365,7 +368,7 @@ impl<'a> Debug for PwPodSequence<'a> { s.field("unit", &self.unit); s.field( "controls", - &debug_fn(|f| { + &fmt::from_fn(|f| { let mut l = f.debug_list(); let mut parser = self.controls; while parser.len() > 0 { @@ -373,7 +376,7 @@ impl<'a> Debug for PwPodSequence<'a> { Ok(c) => l.entry(&c), Err(e) => { let e = ErrorFmt(e); - l.entry(&debug_fn(|f| { + l.entry(&fmt::from_fn(|f| { write!(f, "Could not read control element: {}", &e) })); break; @@ -404,7 +407,7 @@ impl<'a> Debug for PwPodStruct<'a> { let e = ErrorFmt(e); s.field( &field, - &debug_fn(|f| write!(f, "Could not parse struct field: {}", &e)), + &fmt::from_fn(|f| write!(f, "Could not parse struct field: {}", &e)), ); break; } @@ -423,7 +426,7 @@ impl<'a> Debug for PwPodArray<'a> { Ok(e) => list.entry(&e), Err(e) => { let e = ErrorFmt(e); - list.entry(&debug_fn(|f| { + list.entry(&fmt::from_fn(|f| { write!(f, "Could not parse array element: {}", &e) })); break; diff --git a/src/tasks/connector.rs b/src/tasks/connector.rs index 85753771..9ecf51be 100644 --- a/src/tasks/connector.rs +++ b/src/tasks/connector.rs @@ -15,12 +15,11 @@ use { state::{ConnectorData, OutputData, State}, tree::{OutputNode, WsMoveConfig, move_ws_to_output}, utils::{ - asyncevent::AsyncEvent, clonecell::CloneCell, debug_fn::debug_fn, - hash_map_ext::HashMapExt, rc_eq::RcEq, + asyncevent::AsyncEvent, clonecell::CloneCell, hash_map_ext::HashMapExt, rc_eq::RcEq, }, }, jay_config::video::Transform, - std::{cell::Cell, collections::VecDeque, rc::Rc}, + std::{cell::Cell, collections::VecDeque, fmt, rc::Rc}, }; pub fn handle(state: &Rc, connector: &Rc) { @@ -475,7 +474,7 @@ impl ConnectorHandler { } fn create_description(info: &MonitorInfo) -> String { - debug_fn(|f| { + fmt::from_fn(|f| { let mut needs_space = false; let id = &info.output_id; for s in [&id.manufacturer, &id.model, &id.serial_number] { diff --git a/src/utils.rs b/src/utils.rs index 275faa64..ea3ba668 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -14,7 +14,6 @@ pub mod clone3; pub mod clonecell; pub mod compat; pub mod copyhashmap; -pub mod debug_fn; pub mod double_buffered; pub mod double_click_state; pub mod errorfmt; diff --git a/src/utils/debug_fn.rs b/src/utils/debug_fn.rs deleted file mode 100644 index 7f09a9f3..00000000 --- a/src/utils/debug_fn.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::fmt::{Debug, Display, Formatter}; - -pub fn debug_fn(f: F) -> Printable -where - F: Fn(&mut Formatter<'_>) -> std::fmt::Result, -{ - Printable { f } -} - -pub struct Printable { - f: F, -} - -impl Debug for Printable -where - F: Fn(&mut Formatter<'_>) -> std::fmt::Result, -{ - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - (self.f)(f) - } -} - -impl Display for Printable -where - F: Fn(&mut Formatter<'_>) -> std::fmt::Result, -{ - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - (self.f)(f) - } -}