Skip to content

Commit 153c2e4

Browse files
committed
Implement From<&'a &'static str> for Arguments<'a>
1 parent 11467b1 commit 153c2e4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

library/core/src/fmt/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::mem;
1010
use crate::num::fmt as numfmt;
1111
use crate::ops::Deref;
1212
use crate::result;
13+
use crate::slice;
1314
use crate::str;
1415

1516
mod builders;
@@ -422,6 +423,14 @@ impl Display for Arguments<'_> {
422423
}
423424
}
424425

426+
#[stable(feature = "rust1", since = "1.0.0")]
427+
impl<'a> From<&'a &'static str> for Arguments<'a> {
428+
#[inline]
429+
fn from(value: &'a &'static str) -> Self {
430+
Self::new_const(slice::from_ref(value))
431+
}
432+
}
433+
425434
/// `?` formatting.
426435
///
427436
/// `Debug` should format the output in a programmer-facing, debugging context.

library/core/tests/fmt/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ fn test_format_flags() {
1111
assert_eq!(format!("{: >3}", 'a'), " a");
1212
}
1313

14+
#[test]
15+
fn test_arguments_from_str() {
16+
assert_eq!(core::fmt::Arguments::from(&"a string literal").to_string(), "a string literal");
17+
18+
assert_eq!(core::fmt::Arguments::from(&"a string literal").as_str(), Some("a string literal"));
19+
}
20+
1421
#[test]
1522
fn test_pointer_formats_data_pointer() {
1623
let b: &[u8] = b"";

0 commit comments

Comments
 (0)