1
0
Fork 0
forked from wry/wry

all: replace debug_fn with fmt::from_fn

This commit is contained in:
Julian Orth 2026-02-13 11:13:37 +01:00
parent 0932ad11b5
commit b3c46bf52d
11 changed files with 41 additions and 70 deletions

View file

@ -2,11 +2,11 @@ use {
crate::{ crate::{
cli::{GlobalArgs, IdleArgs, duration::parse_duration}, cli::{GlobalArgs, IdleArgs, duration::parse_duration},
tools::tool_client::{Handle, ToolClient, with_tool_client}, 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}, wire::{JayIdleId, WlSurfaceId, jay_compositor, jay_idle},
}, },
clap::{Args, Subcommand}, clap::{Args, Subcommand},
std::{cell::Cell, rc::Rc}, std::{cell::Cell, fmt, rc::Rc},
}; };
#[derive(Subcommand, Debug, Default)] #[derive(Subcommand, Debug, Default)]
@ -105,7 +105,7 @@ impl Idle {
}); });
tc.round_trip().await; tc.round_trip().await;
let interval = |iv: u64| { let interval = |iv: u64| {
debug_fn(move |f| { fmt::from_fn(move |f| {
let minutes = iv / 60; let minutes = iv / 60;
let seconds = iv % 60; let seconds = iv % 60;
if minutes == 0 && seconds == 0 { if minutes == 0 && seconds == 0 {

View file

@ -7,9 +7,7 @@ use {
ifs::wl_output::BlendSpace, ifs::wl_output::BlendSpace,
scale::Scale, scale::Scale,
tools::tool_client::{Handle, ToolClient, with_tool_client}, tools::tool_client::{Handle, ToolClient, with_tool_client},
utils::{ utils::{errorfmt::ErrorFmt, ordered_float::F64, transform_ext::TransformExt},
debug_fn::debug_fn, errorfmt::ErrorFmt, ordered_float::F64, transform_ext::TransformExt,
},
wire::{JayRandrId, jay_compositor, jay_randr}, wire::{JayRandrId, jay_compositor, jay_randr},
}, },
clap::{ clap::{
@ -21,7 +19,7 @@ use {
linearize::LinearizeExt, linearize::LinearizeExt,
std::{ std::{
cell::RefCell, cell::RefCell,
fmt::{Display, Formatter}, fmt::{self, Display, Formatter},
rc::Rc, rc::Rc,
str::FromStr, str::FromStr,
time::Duration, time::Duration,
@ -1067,7 +1065,7 @@ impl Randr {
if let Some(p) = &o.native_gamut { if let Some(p) = &o.native_gamut {
println!( println!(
" native gamut:{}", " native gamut:{}",
debug_fn(|f| { fmt::from_fn(|f| {
if o.use_native_gamut { if o.use_native_gamut {
f.write_str(" (used for default color space)")?; f.write_str(" (used for default color space)")?;
} }

View file

@ -2,9 +2,10 @@ use {
crate::{ crate::{
cmm::{cmm_eotf::Eotf, cmm_primaries::Primaries}, cmm::{cmm_eotf::Eotf, cmm_primaries::Primaries},
theme::Color, theme::Color,
utils::{debug_fn::debug_fn, ordered_float::F64}, utils::ordered_float::F64,
}, },
std::{ std::{
fmt,
fmt::{Debug, Formatter}, fmt::{Debug, Formatter},
hash::{Hash, Hasher}, hash::{Hash, Hasher},
marker::PhantomData, marker::PhantomData,
@ -52,7 +53,7 @@ impl<T, U> Debug for ColorMatrix<T, U> {
} }
fn format_matrix<'a>(m: &'a [[F64; 4]; 3]) -> impl Debug + use<'a> { 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 let iter = m
.iter() .iter()
.copied() .copied()

View file

@ -35,7 +35,6 @@ use {
utils::{ utils::{
asyncevent::AsyncEvent, asyncevent::AsyncEvent,
copyhashmap::CopyHashMap, copyhashmap::CopyHashMap,
debug_fn::debug_fn,
errorfmt::ErrorFmt, errorfmt::ErrorFmt,
numcell::NumCell, numcell::NumCell,
oserror::OsError, oserror::OsError,
@ -83,6 +82,7 @@ use {
regex::Regex, regex::Regex,
std::{ std::{
cell::Cell, cell::Cell,
fmt,
hash::Hash, hash::Hash,
ops::Deref, ops::Deref,
rc::{Rc, Weak}, rc::{Rc, Weak},
@ -273,7 +273,7 @@ impl ConfigProxyHandler {
LogLevel::Debug => Level::Debug, LogLevel::Debug => Level::Debug,
LogLevel::Trace => Level::Trace, LogLevel::Trace => Level::Trace,
}; };
let debug = debug_fn(|fmt| { let debug = fmt::from_fn(|fmt| {
if let Some(file) = file { if let Some(file) = file {
write!(fmt, "{}", file)?; write!(fmt, "{}", file)?;
if let Some(line) = line { if let Some(line) = line {

View file

@ -16,7 +16,6 @@ use {
asyncevent::AsyncEvent, asyncevent::AsyncEvent,
buffd::{EiMsgFormatter, EiMsgParser, EiMsgParserError, OutBufferSwapchain}, buffd::{EiMsgFormatter, EiMsgParser, EiMsgParserError, OutBufferSwapchain},
clonecell::CloneCell, clonecell::CloneCell,
debug_fn::debug_fn,
errorfmt::ErrorFmt, errorfmt::ErrorFmt,
numcell::NumCell, numcell::NumCell,
pid_info::{PidInfo, get_pid_info, get_socket_creds}, pid_info::{PidInfo, get_pid_info, get_socket_creds},
@ -27,7 +26,7 @@ use {
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
error::Error, error::Error,
fmt::Debug, fmt::{self, Debug},
mem, mem,
ops::DerefMut, ops::DerefMut,
rc::Rc, rc::Rc,
@ -128,7 +127,7 @@ impl EiClients {
log::info!( log::info!(
"Client {} connected{:?}", "Client {} connected{:?}",
data.id, data.id,
debug_fn(|fmt| { fmt::from_fn(|fmt| {
if let Some(p) = &data.pid_info { if let Some(p) = &data.pid_info {
write!(fmt, ", pid: {}, uid: {}, comm: {:?}", p.pid, p.uid, p.comm)?; write!(fmt, ", pid: {}, uid: {}, comm: {:?}", p.pid, p.uid, p.comm)?;
} }

View file

@ -9,13 +9,15 @@ use {
SPA_VIDEO_FORMAT_UNKNOWN, SPA_VIDEO_FORMAT_xBGR_210LE, SPA_VIDEO_FORMAT_xRGB_210LE, SPA_VIDEO_FORMAT_UNKNOWN, SPA_VIDEO_FORMAT_xBGR_210LE, SPA_VIDEO_FORMAT_xRGB_210LE,
SpaVideoFormat, SpaVideoFormat,
}, },
utils::debug_fn::debug_fn,
}, },
ahash::AHashMap, ahash::AHashMap,
ash::vk, ash::vk,
jay_config::video::Format as ConfigFormat, jay_config::video::Format as ConfigFormat,
once_cell::sync::Lazy, once_cell::sync::Lazy,
std::fmt::{Debug, Write}, std::{
fmt,
fmt::{Debug, Write},
},
}; };
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -134,7 +136,7 @@ const fn fourcc_code(a: char, b: char, c: char, d: char) -> u32 {
#[expect(dead_code)] #[expect(dead_code)]
pub fn debug(fourcc: u32) -> impl Debug { 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 as u8 as char)?;
fmt.write_char((fourcc >> 8) as u8 as char)?; fmt.write_char((fourcc >> 8) as u8 as char)?;
fmt.write_char((fourcc >> 16) as u8 as char)?; fmt.write_char((fourcc >> 16) as u8 as char)?;

View file

@ -11,7 +11,7 @@ use {
wl_surface::zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2, wl_surface::zwp_input_popup_surface_v2::ZwpInputPopupSurfaceV2,
}, },
keyboard::KeyboardState, keyboard::KeyboardState,
utils::{clonecell::CloneCell, debug_fn::debug_fn, smallmap::SmallMap}, utils::{clonecell::CloneCell, smallmap::SmallMap},
wire::ZwpInputPopupSurfaceV2Id, wire::ZwpInputPopupSurfaceV2Id,
}, },
kbvm::{ kbvm::{
@ -24,7 +24,7 @@ use {
}, },
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
fmt::Write, fmt::{self, Write},
rc::Rc, rc::Rc,
}, },
}; };
@ -154,7 +154,7 @@ impl UnicodeInput {
let _ = write!(self.text, "U+{:x}", self.cp); let _ = write!(self.text, "U+{:x}", self.cp);
self.cursor = self.text.len() as _; self.cursor = self.text.len() as _;
if let Some(char) = char::from_u32(self.cp) { if let Some(char) = char::from_u32(self.cp) {
let s = debug_fn(|f| { let s = fmt::from_fn(|f| {
if char == '\n' { if char == '\n' {
f.write_str("\\n") f.write_str("\\n")
} else { } else {

View file

@ -31,9 +31,12 @@ use {
SpaVideoTransferFunction, 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 { trait PwPodObjectDebugger: Sync {
@ -62,7 +65,7 @@ where
s.field("flags", &value.flags) s.field("flags", &value.flags)
.field( .field(
"pod", "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() .finish()
} }
@ -83,16 +86,16 @@ where
.field("flags", &c.flags) .field("flags", &c.flags)
.field( .field(
"elements", "elements",
&debug_fn(|fmt| { &fmt::from_fn(|fmt| {
array_body_debug(fmt, c.elements, |l, p| { array_body_debug(fmt, c.elements, |l, p| {
match p.read_pod_body_packed(ty, c.elements.child_len) { match p.read_pod_body_packed(ty, c.elements.child_len) {
Ok(p) => { Ok(p) => {
l.entry(&debug_fn(|fmt| f(fmt, p))); l.entry(&fmt::from_fn(|fmt| f(fmt, p)));
true true
} }
Err(e) => { Err(e) => {
let e = ErrorFmt(e); let e = ErrorFmt(e);
l.entry(&debug_fn(|fmt| { l.entry(&fmt::from_fn(|fmt| {
write!(fmt, "Could not read choice element: {}", e) write!(fmt, "Could not read choice element: {}", e)
})); }));
false false
@ -151,7 +154,7 @@ where
} }
Err(e) => { Err(e) => {
let e = ErrorFmt(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 false
} }
}) })
@ -334,18 +337,18 @@ impl<'a> Debug for PwPodObject<'a> {
s.field("id", id); s.field("id", id);
s.field( s.field(
"props", "props",
&debug_fn(|f| { &fmt::from_fn(|f| {
let mut l = f.debug_list(); let mut l = f.debug_list();
let mut parser = self.probs; let mut parser = self.probs;
while parser.len() > 0 { while parser.len() > 0 {
match parser.read_prop() { match parser.read_prop() {
Ok(p) => match debugger { 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), _ => l.entry(&p),
}, },
Err(e) => { Err(e) => {
let e = ErrorFmt(e); let e = ErrorFmt(e);
l.entry(&debug_fn(|f| { l.entry(&fmt::from_fn(|f| {
write!(f, "Could not read object property: {}", &e) write!(f, "Could not read object property: {}", &e)
})); }));
break; break;
@ -365,7 +368,7 @@ impl<'a> Debug for PwPodSequence<'a> {
s.field("unit", &self.unit); s.field("unit", &self.unit);
s.field( s.field(
"controls", "controls",
&debug_fn(|f| { &fmt::from_fn(|f| {
let mut l = f.debug_list(); let mut l = f.debug_list();
let mut parser = self.controls; let mut parser = self.controls;
while parser.len() > 0 { while parser.len() > 0 {
@ -373,7 +376,7 @@ impl<'a> Debug for PwPodSequence<'a> {
Ok(c) => l.entry(&c), Ok(c) => l.entry(&c),
Err(e) => { Err(e) => {
let e = ErrorFmt(e); let e = ErrorFmt(e);
l.entry(&debug_fn(|f| { l.entry(&fmt::from_fn(|f| {
write!(f, "Could not read control element: {}", &e) write!(f, "Could not read control element: {}", &e)
})); }));
break; break;
@ -404,7 +407,7 @@ impl<'a> Debug for PwPodStruct<'a> {
let e = ErrorFmt(e); let e = ErrorFmt(e);
s.field( s.field(
&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; break;
} }
@ -423,7 +426,7 @@ impl<'a> Debug for PwPodArray<'a> {
Ok(e) => list.entry(&e), Ok(e) => list.entry(&e),
Err(e) => { Err(e) => {
let e = ErrorFmt(e); let e = ErrorFmt(e);
list.entry(&debug_fn(|f| { list.entry(&fmt::from_fn(|f| {
write!(f, "Could not parse array element: {}", &e) write!(f, "Could not parse array element: {}", &e)
})); }));
break; break;

View file

@ -15,12 +15,11 @@ use {
state::{ConnectorData, OutputData, State}, state::{ConnectorData, OutputData, State},
tree::{OutputNode, WsMoveConfig, move_ws_to_output}, tree::{OutputNode, WsMoveConfig, move_ws_to_output},
utils::{ utils::{
asyncevent::AsyncEvent, clonecell::CloneCell, debug_fn::debug_fn, asyncevent::AsyncEvent, clonecell::CloneCell, hash_map_ext::HashMapExt, rc_eq::RcEq,
hash_map_ext::HashMapExt, rc_eq::RcEq,
}, },
}, },
jay_config::video::Transform, jay_config::video::Transform,
std::{cell::Cell, collections::VecDeque, rc::Rc}, std::{cell::Cell, collections::VecDeque, fmt, rc::Rc},
}; };
pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) { pub fn handle(state: &Rc<State>, connector: &Rc<dyn Connector>) {
@ -475,7 +474,7 @@ impl ConnectorHandler {
} }
fn create_description(info: &MonitorInfo) -> String { fn create_description(info: &MonitorInfo) -> String {
debug_fn(|f| { fmt::from_fn(|f| {
let mut needs_space = false; let mut needs_space = false;
let id = &info.output_id; let id = &info.output_id;
for s in [&id.manufacturer, &id.model, &id.serial_number] { for s in [&id.manufacturer, &id.model, &id.serial_number] {

View file

@ -14,7 +14,6 @@ pub mod clone3;
pub mod clonecell; pub mod clonecell;
pub mod compat; pub mod compat;
pub mod copyhashmap; pub mod copyhashmap;
pub mod debug_fn;
pub mod double_buffered; pub mod double_buffered;
pub mod double_click_state; pub mod double_click_state;
pub mod errorfmt; pub mod errorfmt;

View file

@ -1,30 +0,0 @@
use std::fmt::{Debug, Display, Formatter};
pub fn debug_fn<F>(f: F) -> Printable<F>
where
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
{
Printable { f }
}
pub struct Printable<F> {
f: F,
}
impl<F> Debug for Printable<F>
where
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
(self.f)(f)
}
}
impl<F> Display for Printable<F>
where
F: Fn(&mut Formatter<'_>) -> std::fmt::Result,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
(self.f)(f)
}
}