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:
Ben Gamari 2014-07-16 22:24:42 -04:00
parent 8659889ed9
commit 96072d6efc

View File

@ -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)
}
}