@@ -1018,7 +1018,8 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
1018
1018
}
1019
1019
}
1020
1020
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`.
1022
1023
///
1023
1024
/// # Examples
1024
1025
///
@@ -1030,17 +1031,25 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
1030
1031
/// assert_eq!(format!("{}", value), "a");
1031
1032
/// assert_eq!(format!("{:?}", value), "'a'");
1032
1033
///
1033
- /// let wrapped = fmt::FormatterFn (|f| write!(f, "{value:?}"));
1034
+ /// let wrapped = fmt::from_fn (|f| write!(f, "{value:?}"));
1034
1035
/// assert_eq!(format!("{}", wrapped), "'a'");
1035
1036
/// assert_eq!(format!("{:?}", wrapped), "'a'");
1036
1037
/// ```
1037
1038
#[ 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 )
1039
1048
where
1040
1049
F : Fn ( & mut fmt:: Formatter < ' _ > ) -> fmt:: Result ;
1041
1050
1042
1051
#[ unstable( feature = "debug_closure_helpers" , issue = "117729" ) ]
1043
- impl < F > fmt:: Debug for FormatterFn < F >
1052
+ impl < F > fmt:: Debug for FromFn < F >
1044
1053
where
1045
1054
F : Fn ( & mut fmt:: Formatter < ' _ > ) -> fmt:: Result ,
1046
1055
{
@@ -1050,7 +1059,7 @@ where
1050
1059
}
1051
1060
1052
1061
#[ unstable( feature = "debug_closure_helpers" , issue = "117729" ) ]
1053
- impl < F > fmt:: Display for FormatterFn < F >
1062
+ impl < F > fmt:: Display for FromFn < F >
1054
1063
where
1055
1064
F : Fn ( & mut fmt:: Formatter < ' _ > ) -> fmt:: Result ,
1056
1065
{
0 commit comments