Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::mem;
use crate::num::fmt as numfmt;
use crate::ops::Deref;
use crate::result;
use crate::slice;
use crate::str;

mod builders;
Expand Down Expand Up @@ -422,6 +423,14 @@ impl Display for Arguments<'_> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<&'a &'static str> for Arguments<'a> {
#[inline]
fn from(value: &'a &'static str) -> Self {
Self::new_const(slice::from_ref(value))
}
}

/// `?` formatting.
///
/// `Debug` should format the output in a programmer-facing, debugging context.
Expand Down
7 changes: 7 additions & 0 deletions library/core/tests/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ fn test_format_flags() {
assert_eq!(format!("{: >3}", 'a'), " a");
}

#[test]
fn test_arguments_from_str() {
assert_eq!(core::fmt::Arguments::from(&"a string literal").to_string(), "a string literal");

assert_eq!(core::fmt::Arguments::from(&"a string literal").as_str(), Some("a string literal"));
}

#[test]
fn test_pointer_formats_data_pointer() {
let b: &[u8] = b"";
Expand Down