Skip to content

Commit 80d35ad

Browse files
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 b48f2a5 commit 80d35ad

File tree

6 files changed

+351
-73
lines changed

6 files changed

+351
-73
lines changed

library/alloc/src/fmt.rs

+2
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ pub use core::fmt::{write, Arguments};
563563
pub use core::fmt::{Binary, Octal};
564564
#[stable(feature = "rust1", since = "1.0.0")]
565565
pub use core::fmt::{Debug, Display};
566+
#[unstable(feature = "formatting_options", issue = "118117")]
567+
pub use core::fmt::{DebugAsHex, FormattingOptions, Sign};
566568
#[stable(feature = "rust1", since = "1.0.0")]
567569
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
568570
#[stable(feature = "rust1", since = "1.0.0")]

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
#![feature(extend_one)]
130130
#![feature(fmt_internals)]
131131
#![feature(fn_traits)]
132+
#![feature(formatting_options)]
132133
#![feature(hasher_prefixfree_extras)]
133134
#![feature(inline_const)]
134135
#![feature(inplace_iteration)]

library/alloc/src/string.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
use core::error::Error;
4646
use core::fmt;
47+
use core::fmt::FormattingOptions;
4748
use core::hash;
4849
#[cfg(not(no_global_oom_handling))]
4950
use core::iter::from_fn;
@@ -2605,7 +2606,7 @@ impl<T: fmt::Display + ?Sized> ToString for T {
26052606
#[inline]
26062607
default fn to_string(&self) -> String {
26072608
let mut buf = String::new();
2608-
let mut formatter = core::fmt::Formatter::new(&mut buf);
2609+
let mut formatter = core::fmt::Formatter::new(&mut buf, FormattingOptions::new());
26092610
// Bypass format_args!() to avoid write_str with zero-length strs
26102611
fmt::Display::fmt(self, &mut formatter)
26112612
.expect("a Display implementation returned an error unexpectedly");

0 commit comments

Comments
 (0)