-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for debug_closure_helpers
#117729
Comments
…viper Closure-consuming helper functions for `fmt::Debug` helpers ACP: rust-lang/libs-team#288 Tracking issue: rust-lang#117729
…cuviper Closure-consuming helper functions for `fmt::Debug` helpers ACP: rust-lang/libs-team#288 Tracking issue: rust-lang#117729
Rollup merge of rust-lang#117730 - jmillikin:fmt-debug-helper-fns, r=cuviper Closure-consuming helper functions for `fmt::Debug` helpers ACP: rust-lang/libs-team#288 Tracking issue: rust-lang#117729
Taking inspiration from core::fmt::from_fn<F>(f: F) -> FormatterFn<F>
where
F: Fn(&mut Formatter<'_>) -> Result
{
FormatterFn(f)
} Plus perhaps also
Is there any particular reason it doesn't implement |
With “just” |
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. |
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. |
I would love to see just |
someone would need to PR |
…=Noratrieb Replace `std::fmt:FormatterFn` with `std::fmt::from_fn` Modelled after the suggestion made in [this](rust-lang#117729 (comment)) comment, this should bring this functionality in line with the existing `array::from_fn` & `iter::from_fn`
…=Noratrieb Replace `std::fmt:FormatterFn` with `std::fmt::from_fn` Modelled after the suggestion made in [this](rust-lang#117729 (comment)) comment, this should bring this functionality in line with the existing `array::from_fn` & `iter::from_fn`
Rollup merge of rust-lang#129017 - its-the-shrimp:core_fmt_from_fn, r=Noratrieb Replace `std::fmt:FormatterFn` with `std::fmt::from_fn` Modelled after the suggestion made in [this](rust-lang#117729 (comment)) comment, this should bring this functionality in line with the existing `array::from_fn` & `iter::from_fn`
Is there anything remaining for stabilization? These are super useful. |
The change suggested above has just been merged into master, the description of the issue should be changed to reflect the new API |
Thanks for your work, @its-the-shrimp! |
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: rust-lang/libs-team#288
Public API
Steps / History
fmt::Debug
helpers #117730Unresolved Questions
{orig_method}_with
, for exampleDebugStruct::field_with()
is likeDebugStruct::field()
.DebugMap
struct gotkey_with()
andvalue_with()
, but notentry_with()
-- is it worth adding that?FormatterFn<F>
place a trait bound onF
so that call sites can be tidier?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: