rust-lang / rust-lang/rust

Tracking Issue for `debug_closure_helpers`

Open
#117,729 61 comments 27 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue disposition-merge finished-final-comment-period T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

View all comments

Feature gate: #![feature(debug_closure_helpers)]

This is a tracking issue for adding helpers to core::fmt that can use closures for formatting values.

ACP: https://github.com/rust-lang/libs-team/issues/288

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: #117730
  • Moved FormatterFn / FromFn / from_fn to separate tracking issue: #146705
  • Final comment period (FCP)^1
  • Stabilization PR: #146099
Unresolved Questions
  • Naming: Do any strong preferences exist regarding the new method names?
    • For now I've named them {orig_method}_with, for example DebugStruct::field_with() is like DebugStruct::field().
    • Resolved: The FormatterFn type was renamed to FromFn (and wrapped in from_fn(), the helper methods kept their original names.
  • The DebugMap struct got key_with() and value_with(), but not entry_with() -- is it worth adding that?
  • Should FormatterFn<F> place a trait bound on F so that call sites can be tidier?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the public API and the completed implementation referenced as #117730, then review stabilization PR #146099 and the resolved questions in this issue. Check the stabilization criteria and final comment period status; done means the API is approved and the stabilization work is merged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.