#[cfg(not(no_global_oom_handling))]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
+#[inline]
pub fn format(args: Arguments<'_>) -> string::String {
- let capacity = args.estimated_capacity();
- let mut output = string::String::with_capacity(capacity);
- output.write_fmt(args).expect("a formatting trait implementation returned an error");
- output
+ fn format_inner(args: Arguments<'_>) -> string::String {
+ let capacity = args.estimated_capacity();
+ let mut output = string::String::with_capacity(capacity);
+ output.write_fmt(args).expect("a formatting trait implementation returned an error");
+ output
+ }
+
+ args.as_str().map_or_else(|| format_inner(args), crate::borrow::ToOwned::to_owned)
}