Skip to content

Commit

Permalink
Added struct fmt::FormattingOptions
Browse files Browse the repository at this point in the history
This allows to build custom `std::Formatter`s at runtime.

Also added some related enums and two related methods on `std::Formatter`.
  • Loading branch information
EliasHolzmann authored and gitbot committed Feb 20, 2025
1 parent 1907032 commit 9cf4ef3
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 70 deletions.
2 changes: 2 additions & 0 deletions alloc/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ pub use core::fmt::{Arguments, write};
pub use core::fmt::{Binary, Octal};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Debug, Display};
#[unstable(feature = "formatting_options", issue = "118117")]
pub use core::fmt::{DebugAsHex, FormattingOptions, Sign};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
1 change: 1 addition & 0 deletions alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
#![feature(extend_one_unchecked)]
#![feature(fmt_internals)]
#![feature(fn_traits)]
#![feature(formatting_options)]
#![feature(hasher_prefixfree_extras)]
#![feature(inplace_iteration)]
#![feature(iter_advance_by)]
Expand Down
3 changes: 2 additions & 1 deletion alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#![stable(feature = "rust1", since = "1.0.0")]

use core::error::Error;
use core::fmt::FormattingOptions;
use core::iter::FusedIterator;
#[cfg(not(no_global_oom_handling))]
use core::iter::from_fn;
Expand Down Expand Up @@ -2682,7 +2683,7 @@ impl<T: fmt::Display + ?Sized> ToString for T {
#[inline]
default fn to_string(&self) -> String {
let mut buf = String::new();
let mut formatter = core::fmt::Formatter::new(&mut buf);
let mut formatter = core::fmt::Formatter::new(&mut buf, FormattingOptions::new());
// Bypass format_args!() to avoid write_str with zero-length strs
fmt::Display::fmt(self, &mut formatter)
.expect("a Display implementation returned an error unexpectedly");
Expand Down
Loading

0 comments on commit 9cf4ef3

Please sign in to comment.