Skip to content

Commit ace258b

Browse files
authored
Unrolled build for rust-lang#129017
Rollup merge of rust-lang#129017 - its-the-shrimp:core_fmt_from_fn, r=Noratrieb Replace `std::fmt:FormatterFn` with `std::fmt::from_fn` Modelled after the suggestion made in [this](rust-lang#117729 (comment)) comment, this should bring this functionality in line with the existing `array::from_fn` & `iter::from_fn`
2 parents 91376f4 + 027b19f commit ace258b

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

library/alloc/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ pub use core::fmt::Alignment;
581581
#[stable(feature = "rust1", since = "1.0.0")]
582582
pub use core::fmt::Error;
583583
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
584-
pub use core::fmt::FormatterFn;
584+
pub use core::fmt::{from_fn, FromFn};
585585
#[stable(feature = "rust1", since = "1.0.0")]
586586
pub use core::fmt::{write, Arguments};
587587
#[stable(feature = "rust1", since = "1.0.0")]

library/core/src/fmt/builders.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
10181018
}
10191019
}
10201020

1021-
/// Implements [`fmt::Debug`] and [`fmt::Display`] using a function.
1021+
/// Creates a type whose [`fmt::Debug`] and [`fmt::Display`] impls are provided with the function
1022+
/// `f`.
10221023
///
10231024
/// # Examples
10241025
///
@@ -1030,17 +1031,25 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
10301031
/// assert_eq!(format!("{}", value), "a");
10311032
/// assert_eq!(format!("{:?}", value), "'a'");
10321033
///
1033-
/// let wrapped = fmt::FormatterFn(|f| write!(f, "{value:?}"));
1034+
/// let wrapped = fmt::from_fn(|f| write!(f, "{value:?}"));
10341035
/// assert_eq!(format!("{}", wrapped), "'a'");
10351036
/// assert_eq!(format!("{:?}", wrapped), "'a'");
10361037
/// ```
10371038
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1038-
pub struct FormatterFn<F>(pub F)
1039+
pub fn from_fn<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result>(f: F) -> FromFn<F> {
1040+
FromFn(f)
1041+
}
1042+
1043+
/// Implements [`fmt::Debug`] and [`fmt::Display`] using a function.
1044+
///
1045+
/// Created with [`from_fn`].
1046+
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1047+
pub struct FromFn<F>(F)
10391048
where
10401049
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result;
10411050

10421051
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1043-
impl<F> fmt::Debug for FormatterFn<F>
1052+
impl<F> fmt::Debug for FromFn<F>
10441053
where
10451054
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
10461055
{
@@ -1050,7 +1059,7 @@ where
10501059
}
10511060

10521061
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1053-
impl<F> fmt::Display for FormatterFn<F>
1062+
impl<F> fmt::Display for FromFn<F>
10541063
where
10551064
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
10561065
{

library/core/src/fmt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub enum Alignment {
3434
}
3535

3636
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
37-
pub use self::builders::FormatterFn;
37+
pub use self::builders::{from_fn, FromFn};
3838
#[stable(feature = "debug_builders", since = "1.2.0")]
3939
pub use self::builders::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
4040

0 commit comments

Comments
 (0)