Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Allow tokens to be extracted from slices
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Apr 12, 2015
1 parent 03e4167 commit 60ea73b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ impl ToTokens for TokenTree {
}
}

impl<T: ToTokens> ToTokens for Vec<T> {
impl<'a, T: ToTokens> ToTokens for &'a [T] {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
self.iter()
.flat_map(|t| t.to_tokens(cx).into_iter())
.collect()
}
}

impl<T: ToTokens> ToTokens for Vec<T> {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let slice: &[T] = self;
slice.to_tokens(cx)
}
}

impl<T: ToTokens> ToTokens for Spanned<T> {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
// FIXME: use the span?
Expand Down Expand Up @@ -331,9 +338,7 @@ impl_to_tokens! { P<ast::ImplItem> }
impl_to_tokens! { ast::WhereClause }
impl_to_tokens! { P<ast::Pat> }
impl_to_tokens! { ast::Arm }
impl_to_tokens_lifetime! { &'a [P<ast::Item>] }
impl_to_tokens! { ast::Ty }
impl_to_tokens_lifetime! { &'a [ast::Ty] }
impl_to_tokens! { Generics }
impl_to_tokens! { P<ast::Stmt> }
impl_to_tokens! { P<ast::Expr> }
Expand Down

0 comments on commit 60ea73b

Please sign in to comment.