Skip to content

Commit dbf82c2

Browse files
EliasHolzmanngitbot
authored and
gitbot
committed
Added struct fmt::FormattingOptions
This allows to build custom `std::Formatter`s at runtime. Also added some related enums and two related methods on `std::Formatter`.
1 parent 5906c67 commit dbf82c2

File tree

8 files changed

+349
-70
lines changed

8 files changed

+349
-70
lines changed

alloc/src/fmt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ pub use core::fmt::{Arguments, write};
596596
pub use core::fmt::{Binary, Octal};
597597
#[stable(feature = "rust1", since = "1.0.0")]
598598
pub use core::fmt::{Debug, Display};
599+
#[unstable(feature = "formatting_options", issue = "118117")]
600+
pub use core::fmt::{DebugAsHex, FormattingOptions, Sign};
599601
#[stable(feature = "rust1", since = "1.0.0")]
600602
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
601603
#[stable(feature = "rust1", since = "1.0.0")]

alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
#![feature(extend_one_unchecked)]
118118
#![feature(fmt_internals)]
119119
#![feature(fn_traits)]
120+
#![feature(formatting_options)]
120121
#![feature(hasher_prefixfree_extras)]
121122
#![feature(inplace_iteration)]
122123
#![feature(iter_advance_by)]

alloc/src/string.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#![stable(feature = "rust1", since = "1.0.0")]
4444

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

0 commit comments

Comments
 (0)