We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bc4e33e commit e17c17aCopy full SHA for e17c17a
src/libcore/fmt/mod.rs
@@ -436,12 +436,17 @@ impl<'a> Arguments<'a> {
436
/// #![feature(fmt_as_str)]
437
///
438
/// assert_eq!(format_args!("hello").as_str(), Some("hello"));
439
+ /// assert_eq!(format_args!("").as_str(), Some(""));
440
/// assert_eq!(format_args!("{}", 1).as_str(), None);
441
/// ```
442
#[unstable(feature = "fmt_as_str", issue = "none")]
443
#[inline]
444
pub fn as_str(&self) -> Option<&'a str> {
- if self.args.is_empty() && self.pieces.len() == 1 { Some(self.pieces[0]) } else { None }
445
+ match (self.pieces, self.args) {
446
+ ([], []) => Some(""),
447
+ ([s], []) => Some(s),
448
+ _ => None,
449
+ }
450
}
451
452
0 commit comments