all: replace debug_fn with fmt::from_fn
This commit is contained in:
parent
0932ad11b5
commit
b3c46bf52d
11 changed files with 41 additions and 70 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)")?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<T, U> Debug for ColorMatrix<T, U> {
|
|||
}
|
||||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)?;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<State>, connector: &Rc<dyn Connector>) {
|
||||
|
|
@ -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] {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue