Open
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;
}
pub from_fn<F>(f: F) -> FromFn<F>
where
F: Fn(&mut Formatter<'_>) -> Result
{
FormatterFn(f)
}
pub struct FromFn<F>(F)
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result;
impl<F> fmt::Debug for FromFn<F>
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result;
impl<F> fmt::Display for FromFn<F>
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result;
Steps / History
- Implementation: Closure-consuming helper functions for
fmt::Debug
helpers #117730 - Update to
from_fn
API: Replacestd::fmt:FormatterFn
withstd::fmt::from_fn
#129017 - Final comment period (FCP)1
- Stabilization PR
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()
.
- For now I've named them
- The
DebugMap
struct gotkey_with()
andvalue_with()
, but notentry_with()
-- is it worth adding that? - Should
FormatterFn<F>
place a trait bound onF
so that call sites can be tidier?