From f17d13285c04b71c804d83fdf2eb8e82f0c6096f Mon Sep 17 00:00:00 2001 From: Elias Holzmann <9659253+EliasHolzmann@users.noreply.github.com> Date: Wed, 22 Nov 2023 01:52:13 +0100 Subject: 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`. --- library/alloc/src/fmt.rs | 2 ++ library/alloc/src/lib.rs | 1 + library/alloc/src/string.rs | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/fmt.rs b/library/alloc/src/fmt.rs index 695dddb25ee..e40de13f3d4 100644 --- a/library/alloc/src/fmt.rs +++ b/library/alloc/src/fmt.rs @@ -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")] diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 84f4202c02a..927c3aa23b9 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -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)] diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index e0576c25515..d0d0276c55e 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -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; @@ -2682,7 +2683,7 @@ impl 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"); -- cgit 1.4.1-3-g733a5 From ad8f264e46a3420bc90a94b8047d0a6efde497e8 Mon Sep 17 00:00:00 2001 From: Elias Holzmann <9659253+EliasHolzmann@users.noreply.github.com> Date: Wed, 22 Nov 2023 23:40:01 +0100 Subject: Fixed another broken test --- library/alloc/src/string.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index d0d0276c55e..c5378d78d59 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -43,7 +43,6 @@ #![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; @@ -2683,7 +2682,8 @@ impl ToString for T { #[inline] default fn to_string(&self) -> String { let mut buf = String::new(); - let mut formatter = core::fmt::Formatter::new(&mut buf, FormattingOptions::new()); + let mut formatter = + core::fmt::Formatter::new(&mut buf, core::fmt::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"); -- cgit 1.4.1-3-g733a5