Skip to content

Commit

Permalink
syntax: Generalize ToTokens impl for Vec<T>
Browse files Browse the repository at this point in the history
It will now `flat_map` over the elements of a `Vec<T>` if
`T: ToTokens`
  • Loading branch information
bgamari committed Jul 17, 2014
1 parent 8659889 commit 96072d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/libsyntax/ext/quote.rs
Expand Up @@ -54,9 +54,10 @@ pub mod rt {
}
}

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

Expand Down

0 comments on commit 96072d6

Please sign in to comment.