Skip to content

Commit a72ce78

Browse files
committed
implement Literal::byte_character
without this, the only way to create a `LitKind::Byte` is by doing `"b'a'".parse::<Literal>()`, this solves that by enabling `Literal::byte_character(b'a')`
1 parent 596f278 commit a72ce78

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

proc_macro/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,13 @@ impl Literal {
13371337
Literal::new(bridge::LitKind::Char, symbol, None)
13381338
}
13391339

1340+
/// Byte character literal.
1341+
#[unstable(feature = "proc_macro_byte_character", issue = "115268")]
1342+
pub fn byte_character(byte: u8) -> Literal {
1343+
let string = [byte].escape_ascii().to_string();
1344+
Literal::new(bridge::LitKind::Byte, &string, None)
1345+
}
1346+
13401347
/// Byte string literal.
13411348
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
13421349
pub fn byte_string(bytes: &[u8]) -> Literal {

0 commit comments

Comments
 (0)