mirror of
https://gitee.com/openharmony/third_party_rust_quote
synced 2024-11-27 09:20:35 +00:00
Add append_separated
This commit is contained in:
parent
5232bc9bb8
commit
21d0539fcf
@ -43,12 +43,7 @@ macro_rules! quote_each_token {
|
||||
};
|
||||
|
||||
($tokens:ident # ( $first:ident ) $sep:tt * $($rest:tt)*) => {
|
||||
for (_i, _v) in $first.iter().enumerate() {
|
||||
if _i > 0 {
|
||||
$tokens.append(stringify!($sep));
|
||||
}
|
||||
_v.to_tokens(&mut $tokens);
|
||||
}
|
||||
$tokens.append_separated($first, stringify!($sep));
|
||||
quote_each_token!($tokens $($rest)*);
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
use super::ToTokens;
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -12,6 +13,18 @@ impl Tokens {
|
||||
self.0.push_str(token);
|
||||
self.0.push(' ');
|
||||
}
|
||||
|
||||
pub fn append_separated<T, I>(&mut self, iter: I, sep: &str)
|
||||
where T: ToTokens,
|
||||
I: IntoIterator<Item = T>
|
||||
{
|
||||
for (i, token) in iter.into_iter().enumerate() {
|
||||
if i > 0 {
|
||||
self.append(sep);
|
||||
}
|
||||
token.to_tokens(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Tokens {
|
||||
|
Loading…
Reference in New Issue
Block a user