Skip to content

Revise documentation of NumBuffer and format_into(). - #162158

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
kpreid:numbuffer
Sep 6, 2026
Merged

Revise documentation of NumBuffer and format_into().#162158
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
kpreid:numbuffer

Conversation

@kpreid

@kpreid kpreid commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

The previous documentation was, in my opinion, overly focused on the implementation of these items, rather than how and when to use them. In particular, this new documentation:

  • Begins the format_into() documentation with what it does when called.
  • Specifies that format_into() is a specialized alternative to the more commonly used Display.
  • Specifies that NumBuffer cannot be read or otherwise used by itself.

@rustbot label +A-docs

@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in integer formatting

cc @tgross35

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 1, 2026
@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey

@rustbot rustbot added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Sep 1, 2026

@hanna-kruppe hanna-kruppe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a good improvement, but the “without heap allocation” part is misleading.

r? me @rustbot author

View changes since this review

Comment thread library/core/src/fmt/num.rs Outdated
/// `buf` as storage for the returned string slice.
///
/// This can be used instead of ordinary [`Display`][fmt::Display] formatting to
/// format numbers without any heap allocations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt machinery can be used without heap allocation, e.g., writing to any io::Write impl backed by a stack buffer (which won’t give you a &str for free, but can be combined with str::from_utf8[_unchecked]), or using third party types like ArrayString (which impls fmt::Write and trivially gives you a &str). Maybe just motivate it more generically as “more efficient” without going into details?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right about heap allocation, but I don’t want to say just “this can format numbers more efficiently” because that leads to misconceptions like “Display is gratuitously inefficient”. There should be some qualification that says which situations this is worth doing in. The exact internal difference is that format_into() avoids the dynamic dispatch inherent in fmt, and that’s it, right? I’ve revised the paragraph to:

This method can be used to convert integers to strings without involving the dynamic dispatch that using [Display] would. This may be more efficient in situations where [fmt] is not otherwise used.

@rustbot rustbot assigned hanna-kruppe and unassigned JohnTitor Sep 2, 2026
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 2, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

rustbot commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@kpreid

kpreid commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 5, 2026
@rust-log-analyzer

This comment has been minimized.

The previous documentation was, in my opinion, overly focused on the
implementation of these items, rather than how and when to use them.
This new documentation:

* Begins the `format_into()` documentation with what it does when called.
* Specifies that `format_into()` is a specialized alternative to the more
  commonly used `Display`.
* Specifies that `NumBuffer` cannot be read or otherwise used by itself.
@hanna-kruppe

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6c2b374 has been approved by hanna-kruppe

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 6, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #162032 (remove more trivial regions in evaluate_added_goals_and_make_canonical_response)
 - #161607 (Add #[track_caller] to signed integer div/rem methods)
 - #162339 (Revert "bootstrap: Enable rustdoc mergeable CCI for std and internal docs #161716")
 - #162158 (Revise documentation of `NumBuffer` and `format_into()`.)
@rust-bors
rust-bors Bot merged commit 3b6ec47 into rust-lang:main Sep 6, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 6, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 6, 2026
Rollup merge of #162158 - kpreid:numbuffer, r=hanna-kruppe

Revise documentation of `NumBuffer` and `format_into()`.

The previous documentation was, in my opinion, overly focused on the implementation of these items, rather than how and when to use them. In particular, this new documentation:

* Begins the `format_into()` documentation with what it does when called.
* Specifies that `format_into()` is a specialized alternative to the more commonly used `Display`.
* Specifies that `NumBuffer` cannot be read or otherwise used by itself.

@rustbot label +A-docs
@kpreid
kpreid deleted the numbuffer branch September 6, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants