diff options
| author | Ben Gamari <bgamari.foss@gmail.com> | 2014-07-16 22:24:42 -0400 |
|---|---|---|
| committer | Ben Gamari <bgamari.foss@gmail.com> | 2014-07-16 22:24:42 -0400 |
| commit | 96072d6efc110e81ab6e0a70e2bf9a96a53268b6 (patch) | |
| tree | f34e7994d53a82c472fee3865384bcff7cfd7663 /src/libsyntax/ext | |
| parent | 8659889ed959d1a5921cb18e42d92e7a4cad5903 (diff) | |
| download | rust-96072d6efc110e81ab6e0a70e2bf9a96a53268b6.tar.gz rust-96072d6efc110e81ab6e0a70e2bf9a96a53268b6.zip | |
syntax: Generalize ToTokens impl for Vec<T>
It will now `flat_map` over the elements of a `Vec<T>` if `T: ToTokens`
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index eb1f25143cf..21c5626d16d 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -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) } } |
