syntax: Generalize ToTokens impl for Vec<T>
It will now `flat_map` over the elements of a `Vec<T>` if `T: ToTokens`
This commit is contained in:
parent
8659889ed9
commit
96072d6efc
@ -54,9 +54,10 @@ fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for Vec<TokenTree> {
|
||||
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
|
||||
(*self).clone()
|
||||
impl<T: ToTokens> ToTokens for Vec<T> {
|
||||
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
|
||||
let a = self.iter().flat_map(|t| t.to_tokens(cx).move_iter());
|
||||
FromIterator::from_iter(a)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user