about summary refs log tree commit diff
path: root/library/alloc/src/fmt.rs
AgeCommit message (Collapse)AuthorLines
2025-07-13docs(alloc::fmt): Make `type` optional, instead of matching the empty stringNik Revenco-2/+2
2025-04-12Fix typo in documentationGenYuLi-1/+1
Correct the misspelling of "indentifier" to "identifier" in `library/alloc/src/fmt.rs`.
2024-12-05Added struct `fmt::FormattingOptions`Elias Holzmann-0/+2
This allows to build custom `std::Formatter`s at runtime. Also added some related enums and two related methods on `std::Formatter`.
2024-11-02Rustdoc: added brief colon explanationtuturuu-0/+10
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-08-12std::fmt::FormatterFn -> std::fmt::FromFnschvv31n-1/+1
2024-07-26Fix doc nitsJohn Arundel-2/+1
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-06Mark format! with must_use hintlukas-0/+4
2024-05-12Auto merge of #125012 - RalfJung:format-error, r=Mark-Simulacrum,workingjubileebors-1/+3
io::Write::write_fmt: panic if the formatter fails when the stream does not fail Follow-up to https://github.com/rust-lang/rust/pull/124954
2024-05-11io::Write::write_fmt: panic if the formatter fails when the stream does not failRalf Jung-1/+3
2024-05-09Document proper usage of `fmt::Error` and `fmt()`'s `Result`.Kevin Reid-1/+1
Documentation of these properties previously existed in a lone paragraph in the `fmt` module's documentation: <https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits> However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items.
2024-02-12docs: use correct link, use secondary exampleTristan F-2/+5
2024-02-12style: fmtTristan F.-1/+1
2024-02-12docs: mention round-to-even in precision formattingTristan F-0/+13
2024-02-11Rollup merge of #117740 - majaha:format_docs, r=joshtriplettMatthias Krüger-0/+5
Add some links and minor explanatory comments to `std::fmt` I thought the documentation for the `#` flag could do with a link to the explanation of the `?xXbo` flags, because at that point they haven't been explained yet and it's a bit confusing. I also added that the `0` flag overrides the fill character and alignment flag, here's a [Rust Playgrond](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0d580b7b78b8a2d8c08a2fc7a936ef17) that shows what I mean.
2023-11-10Closure-consuming helper functions for `fmt::Debug` helpersJohn Millikin-0/+2
2023-11-09Remove trailing whitespaceMatt Harding-2/+2
2023-11-09Add note on how 0 flag overrides fill characterMatt Harding-0/+1
2023-11-08Add link to Formatting traits from alternate formsMatt Harding-0/+4
2023-09-03Improve documentation on when signes are printed by defaultRoland Fredenhagen-2/+2
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-4/+4
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-04-20Don't reexport core::fmt::rt from alloc::fmt.Mara Bos-2/+0
2023-01-29Don't re-export private/unstable ArgumentV1 from `alloc`.Mara Bos-1/+1
2022-12-17std::fmt: Use args directly in example codeEvan Jones-2/+2
The lint "clippy::uninlined_format_args" recommends inline variables in format strings. Fix two places in the docs that do not do this. I noticed this because I copy/pasted one example in to my project, then noticed this lint error. This fixes: error: variables can be used directly in the `format!` string --> src/main.rs:30:22 | 30 | let string = format!("{:.*}", decimals, magnitude); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: variables can be used directly in the `format!` string --> src/main.rs:39:2 | 39 | write!(&mut io::stdout(), "{}", args).unwrap();
2022-10-01Detect and reject out-of-range integers in format string literalsColin Baumgarten-1/+1
Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes #102528
2022-05-29remove useless coldConrad Ludgate-3/+2
2022-05-29improve format impl for literalsConrad Ludgate-4/+10
2022-05-01std::fmt: Improved list of formatting macrosElias Holzmann-4/+6
Two improvements: 1. write! can not only receive a `io::Write`, but also a `fmt::Write` as first argument. 2. The description texts now contain links to the actual macros for easier navigation.
2022-05-01std::fmt: Removed reference to Formatter::buf and other private fieldsElias Holzmann-3/+3
Formatter::buf is not a public field and therefore isn't very helpful in user- facing documentation. Also, the other public fields of Formatter were made private during stabilization of std::fmt (4af3494bb0) and can now only be read via accessor methods.
2022-05-01std::fmt: Fix the grammar documentationElias Holzmann-2/+7
According to the grammar documented, the format specifier `{: }` should not be legal because of the whitespace it contains. However, in reality, this is perfectly fine because the actual implementation allows spaces before the closing brace. Fixes #71088. Also, the exact meaning of most of the terminal symbols was not specified, for example the meaning of `identifier`.
2022-05-01std::fmt: Added argument index comments to examples for specifying precisionElias Holzmann-6/+6
The examples for specifying the precision have comments explaining which argument the specifier is referring to. However, for implicit positional arguments, the examples simply talk about "next arg". To make it easier for readers to follow the comments, "next arg" was supplemented with the actual resulting argument index.
2022-05-01std::fmt: Fixed documentation for specifying precision via `.*`Elias Holzmann-5/+11
The documentation stated that in case of the syntax `{<arg>:<spec>.*}`, "the `<arg>` part refers to the value to print, and the precision must come in the input preceding `<arg>`". This is not correct: the <arg> part does indeed refer to the value to print, but the precision does not come in the input preciding arg, but in the next implicit input (as if specified with {}). Fixes #96413.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-3/+3
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-09Fix typo in `std::fmt` docsTitus-1/+1
2021-11-15Give examples of format args capture in the fmt module documentationJosh Triplett-0/+17
2021-10-15Add #[must_use] to remaining alloc functionsJohn Kugelman-0/+1
2021-09-25Apply 16 commits (squashed)Frank Steffahn-16/+12
---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::fmt ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::{rc, sync} ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::string ---------- Fix spacing for links inside code blocks in alloc::vec ---------- Fix spacing for links inside code blocks in core::option ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in core::result ---------- Fix spacing for links inside code blocks in core::{iter::{self, iterator}, stream::stream, poll} ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{fs, path} ---------- Fix spacing for links inside code blocks in std::{collections, time} ---------- Fix spacing for links inside code blocks in and make formatting of `&str`-like types consistent in std::ffi::{c_str, os_str} ---------- Fix spacing for links inside code blocks, and improve link tooltips in std::ffi ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{io::{self, buffered::{bufreader, bufwriter}, cursor, util}, net::{self, addr}} ---------- Fix typo in link to `into` for `OsString` docs ---------- Remove tooltips that will probably become redundant in the future ---------- Apply suggestions from code review Replacing `…std/primitive.reference.html` paths with just `reference` Co-authored-by: Joshua Nelson <github@jyn.dev> ---------- Also replace `…std/primitive.reference.html` paths with just `reference` in `core::pin`
2021-07-29Fix may not to appropriate might not or must notAli Malik-2/+2
2021-05-05alloc: Add unstable Cfg feature `no-global_oom_handling`John Ericson-0/+2
For certain sorts of systems, programming, it's deemed essential that all allocation failures be explicitly handled where they occur. For example, see Linus Torvald's opinion in [1]. Merely not calling global panic handlers, or always `try_reserving` first (for vectors), is not deemed good enough, because the mere presence of the global OOM handlers is burdens static analysis. One option for these projects to use rust would just be to skip `alloc`, rolling their own allocation abstractions. But this would, in my opinion be a real shame. `alloc` has a few `try_*` methods already, and we could easily have more. Features like custom allocator support also demonstrate and existing to support diverse use-cases with the same abstractions. A natural way to add such a feature flag would a Cargo feature, but there are currently uncertainties around how std library crate's Cargo features may or not be stable, so to avoid any risk of stabilizing by mistake we are going with a more low-level "raw cfg" token, which cannot be interacted with via Cargo alone. Note also that since there is no notion of "default cfg tokens" outside of Cargo features, we have to invert the condition from `global_oom_handling` to to `not(no_global_oom_handling)`. This breaks the monotonicity that would be important for a Cargo feature (i.e. turning on more features should never break compatibility), but it doesn't matter for raw cfg tokens which are not intended to be "constraint solved" by Cargo or anything else. To support this use-case we create a new feature, "global-oom-handling", on by default, and put the global OOM handler infra and everything else it that depends on it behind it. By default, nothing is changed, but users concerned about global handling can make sure it is disabled, and be confident that all OOM handling is local and explicit. For this first iteration, non-flat collections are outright disabled. `Vec` and `String` don't yet have `try_*` allocation methods, but are kept anyways since they can be oom-safely created "from parts", and we hope to add those `try_` methods in the future. [1]: https://lore.kernel.org/lkml/CAHk-=wh_sNLoz84AUUzuqXEsYH35u=8HV3vK-jbRbJ_B-JjGrg@mail.gmail.com/
2021-03-27Auto merge of #78618 - workingjubilee:ieee754-fmt, r=m-ou-sebors-3/+2
Add IEEE 754 compliant fmt/parse of -0, infinity, NaN This pull request improves the Rust float formatting/parsing libraries to comply with IEEE 754's formatting expectations around certain special values, namely signed zero, the infinities, and NaN. It also adds IEEE 754 compliance tests that, while less stringent in certain places than many of the existing flt2dec/dec2flt capability tests, are intended to serve as the beginning of a roadmap to future compliance with the standard. Some relevant documentation is also adjusted with clarifying remarks. This PR follows from discussion in https://github.com/rust-lang/rfcs/issues/1074, and closes #24623. The most controversial change here is likely to be that -0 is now printed as -0. Allow me to explain: While there appears to be community support for an opt-in toggle of printing floats as if they exist in the naively expected domain of numbers, i.e. not the extended reals (where floats live), IEEE 754-2019 is clear that a float converted to a string should be capable of being transformed into the original floating point bit-pattern when it satisfies certain conditions (namely, when it is an actual numeric value i.e. not a NaN and the original and destination float width are the same). -0 is given special attention here as a value that should have its sign preserved. In addition, the vast majority of other programming languages not only output `-0` but output `-0.0` here. While IEEE 754 offers a broad leeway in how to handle producing what it calls a "decimal character sequence", it is clear that the operations a language provides should be capable of round tripping, and it is confusing to advertise the f32 and f64 types as binary32 and binary64 yet have the most basic way of producing a string and then reading it back into a floating point number be non-conformant with the standard. Further, existing documentation suggested that e.g. -0 would be printed with -0 regardless of the presence of the `+` fmt character, but it prints "+0" instead if given such (which was what led to the opening of #24623). There are other parsing and formatting issues for floating point numbers which prevent Rust from complying with the standard, as well as other well-documented challenges on the arithmetic level, but I hope that this can be the beginning of motion towards solving those challenges.
2021-03-22Update signed fmt/-0f32 docsJubilee Young-3/+2
"semantic equivalence" is too strong a phrasing here, which is why actually explaining what kind of circumstances might produce a -0 was chosen instead.
2021-03-22Update library/alloc/src/fmt.rsAndrew Lamb-1/+1
2021-03-22Make # format easier to discoverAndrew Lamb-1/+5
2021-01-01Improve grammar in documentation of format stringsFrank Steffahn-4/+5
2020-11-07Convert a bunch of intra-doc linksCamelid-6/+6
2020-08-21Apply suggestions from code reviewLeSeulArtichaut-3/+0
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-21Use intra-doc-links in `alloc`LeSeulArtichaut-22/+16
2020-08-11word changeJosé Luis Cruz-1/+1
there are three significantly different things printed below
2020-07-29Link to syntax section when referencing itTomasz Miąsko-1/+1
2020-07-27mv std libs to library/mark-0/+588