mirror of
https://gitee.com/openharmony/third_party_rust_quote
synced 2024-11-23 23:29:43 +00:00
Remove ByteStr
Users can now build a `Literal::byte_string(bytes)` and interpolate that.
This commit is contained in:
parent
9ae2877249
commit
4189356a5d
@ -80,7 +80,7 @@ mod tokens;
|
||||
pub use tokens::Tokens;
|
||||
|
||||
mod to_tokens;
|
||||
pub use to_tokens::{ByteStr, ToTokens};
|
||||
pub use to_tokens::ToTokens;
|
||||
|
||||
// Not public API.
|
||||
#[doc(hidden)]
|
||||
|
@ -149,14 +149,3 @@ impl ToTokens for bool {
|
||||
tokens.append(tt(TokenNode::Term(Term::intern(word))));
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrap a `&str` so it interpolates as a byte-string: `b"abc"`.
|
||||
#[derive(Debug)]
|
||||
pub struct ByteStr<'a>(pub &'a str);
|
||||
|
||||
impl<'a> ToTokens for ByteStr<'a> {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
let lit = Literal::byte_string(self.0.as_bytes());
|
||||
tokens.append(tt(TokenNode::Literal(lit)));
|
||||
}
|
||||
}
|
||||
|
@ -183,22 +183,6 @@ fn test_string() {
|
||||
assert_eq!(expected, tokens.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_byte_str() {
|
||||
let s = quote::ByteStr("\0 a 'b \" c");
|
||||
let tokens = quote!(#s);
|
||||
let expected = "b\"\\0 a \'b \\\" c\"";
|
||||
assert_eq!(expected, tokens.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_byte_str_escape() {
|
||||
let s = quote::ByteStr("\u{3c3} \\ \" \n");
|
||||
let tokens = quote!(#s);
|
||||
let expected = "b\"\\xCF\\x83 \\\\ \\\" \\n\"";
|
||||
assert_eq!(expected, tokens.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ident() {
|
||||
let foo = Term::intern("Foo");
|
||||
|
Loading…
Reference in New Issue
Block a user