Skip to content

Commit d009b0d

Browse files
committed
proc_macro_c_str_literals: Implement Literal::c_string constructor
1 parent ee87b72 commit d009b0d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

proc_macro/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mod diagnostic;
4545
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
4646
pub use diagnostic::{Diagnostic, Level, MultiSpan};
4747

48+
use std::ffi::CStr;
4849
use std::ops::{Range, RangeBounds};
4950
use std::path::PathBuf;
5051
use std::str::FromStr;
@@ -1351,6 +1352,13 @@ impl Literal {
13511352
Literal::new(bridge::LitKind::ByteStr, &string, None)
13521353
}
13531354

1355+
/// C string literal.
1356+
#[unstable(feature = "proc_macro_c_str_literals", issue = "119750")]
1357+
pub fn c_string(string: &CStr) -> Literal {
1358+
let string = string.to_bytes().escape_ascii().to_string();
1359+
Literal::new(bridge::LitKind::CStr, &string, None)
1360+
}
1361+
13541362
/// Returns the span encompassing this literal.
13551363
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
13561364
pub fn span(&self) -> Span {

0 commit comments

Comments
 (0)