Repository navigation
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
Feature gate: #![feature(debug_closure_helpers)]
This is a tracking issue for adding helpers to core::fmt that can use closures for formatting values.
Public API
// core::fmt
impl DebugList<'_, '_> {
fn entry_with<F>(&mut self, entry_fmt: F) -> &mut Self
where
F: FnOnce(&mut Formatter) -> fmt::Result;
}
impl DebugMap<'_, '_> {
fn key_with<F>(&mut self, key_fmt: F) -> &mut Self
where
F: FnOnce(&mut Formatter) -> fmt::Result;
fn value_with<F>(&mut self, value_fmt: F) -> &mut Self
where
F: FnOnce(&mut Formatter) -> fmt::Result;
}
impl DebugSet<'_, '_> {
fn entry_with<F>(&mut self, entry_fmt: F) -> &mut Self
where
F: FnOnce(&mut Formatter) -> fmt::Result;
}
impl DebugStruct<'_, '_> {
fn field_with<F>(&mut self, name: &str, field_fmt: F) -> &mut Self
where
F: FnOnce(&mut Formatter) -> fmt::Result;
}
impl DebugTuple<'_, '_> { // also DebugSet
fn field_with<F>(&mut self, field_fmt: F) -> &mut Self
where
F: FnOnce(&mut Formatter) -> fmt::Result;
}Steps / History
- Implementation: Closure-consuming helper functions for
fmt::Debughelpers #117730 - Moved
FormatterFn/FromFn/from_fnto separate tracking issue: Tracking Issue forfmt_from_fn#146705 - Final comment period (FCP)1
- Stabilization PR: Stabilize
debug_closure_helpers#146099
Unresolved Questions
- Naming: Do any strong preferences exist regarding the new method names?
- For now I've named them
{orig_method}_with, for exampleDebugStruct::field_with()is likeDebugStruct::field(). - Resolved: The
FormatterFntype was renamed toFromFn(and wrapped infrom_fn(), the helper methods kept their original names.
- For now I've named them
- The
DebugMapstruct gotkey_with()andvalue_with(), but notentry_with()-- is it worth adding that?- Resolved to not add
entry_with; see ReplaceDebug::{key_with, value_with}withDebugMap::entry_withlibs-team#563 (comment)
- Resolved to not add
- Should
FormatterFn<F>place a trait bound onFso that call sites can be tidier?
Footnotes
Reacted by Val, Will Jones, toymil, Max Wase, ahoyiski, Matt Johnston, Tim Kurdov, Ben, José Luis Cruz, Mrmaxmeier and 17 more
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
Auto merge of rust-lang#117730 - jmillikin:fmt-debug-helper-fns, r=cu…
Rollup merge of rust-lang#117730 - jmillikin:fmt-debug-helper-fns, r=…
Unrolled build for rust-lang#117730
QuineDot commentedon Dec 3, 2023
Taking inspiration from
iter::from_fn, I suggest a module level helper function:Plus perhaps also
structtofmt::FromFnstructdefinitionIs there any particular reason it doesn't implement
Binary,LowerExp, etc? (Why bothDebugandDisplaybut not all formats?)steffahn commentedon Mar 3, 2024
With “just”
DebugandDisplayit would kind-of follow the precedent offmt::Arguments<'_>.workingjubilee commentedon May 5, 2024
these are really nice btw. I think QuineDot's suggestion could be a cool refactoring of this, but it's very nice to be able to basically randomly throw in a simple closure that provides debug formatting, without having to roll the internals yourself, since it's just... like, the case you're most likely doing this, you're already implementing some kind of explicit Debug or "Debug adapter" and you don't wanna have to do another one for every custom field.
workingjubilee commentedon May 6, 2024
QuineDot's suggestion is in fact very close to one of the listed alternatives in the original idea! The main difference is the use of a free higher-order function instead of a constructor, which might be better for type inference reasons.
01mf02 commentedon Jun 18, 2024
I would love to see just
fmt::from_fnstabilised, as suggested by @QuineDot. The symmetry withiter::from_fnis apparent, and this seems relatively uncontroversial. What is the status of stabilising this?workingjubilee commentedon Jun 29, 2024
someone would need to PR
fmt::from_fn, to start.Rollup merge of rust-lang#129017 - its-the-shrimp:core_fmt_from_fn, r…
Rollup merge of rust-lang#129017 - its-the-shrimp:core_fmt_from_fn, r…
Unrolled build for rust-lang#129017
SUPERCILEX commentedon Aug 13, 2024
Is there anything remaining for stabilization? These are super useful.
80 remaining items
jendrikw commentedon Apr 18, 2026
This feature was stabilized and released in Rust 1.93 (https://blog.rust-lang.org/2026/01/22/Rust-1.93.0/). Should this issue (and the PR?) be closed?
tgross35 commentedon Apr 18, 2026
Are you referring to
fmt_from_fn? That was split off from this one #146705, the remaining API here is still unstable https://doc.rust-lang.org/std/fmt/struct.DebugList.html#method.entry_with.jendrikw commentedon Apr 19, 2026
I missed that the feature was split. Sorry to bother you.
Fix Rust wrapper on stable Rust (specta typescript opt-in)
Rollup merge of rust-lang#159302 - connortsui20:dyn-debug-helpers, r=…
Rollup merge of rust-lang#159302 - connortsui20:dyn-debug-helpers, r=…
Rollup merge of rust-lang#159302 - connortsui20:dyn-debug-helpers, r=…
Rollup merge of rust-lang#159302 - connortsui20:dyn-debug-helpers, r=…
Unrolled build for #159302
feat(next): add Tauri command IPC infrastructure (P10 chunk 10.1)
Rollup merge of rust-lang#146099 - coolreader18:stabilize-debug_closu…
Unrolled build for #146099 in rollup 163774