diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-02-20 13:31:52 +0100 |
---|---|---|
committer | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-03-30 13:52:30 +0200 |
commit | 09c75e3750858577efe09a51416546b1e5cc0f5c (patch) | |
tree | a2dbba7925f0b1af4667f6172821cfeedd362247 | |
parent | f84d6127fe60a968bf331ebb9cec58b16df86852 (diff) | |
download | gcc-09c75e3750858577efe09a51416546b1e5cc0f5c.zip gcc-09c75e3750858577efe09a51416546b1e5cc0f5c.tar.gz gcc-09c75e3750858577efe09a51416546b1e5cc0f5c.tar.bz2 |
libproc_macro: Implement Extend for TokenStream
Implement extension from TokenTree and TokenStream iterators on
TokenStream rust type.
ChangeLog:
* librust/proc_macro/rust/bridge/token_stream.rs: Add internal
implementation for TokenStream extension.
* librust/proc_macro/rust/lib.rs: Add call to internal.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | librust/proc_macro/rust/bridge/token_stream.rs | 18 | ||||
-rw-r--r-- | librust/proc_macro/rust/lib.rs | 8 |
2 files changed, 22 insertions, 4 deletions
diff --git a/librust/proc_macro/rust/bridge/token_stream.rs b/librust/proc_macro/rust/bridge/token_stream.rs index 7135a0f..027f450 100644 --- a/librust/proc_macro/rust/bridge/token_stream.rs +++ b/librust/proc_macro/rust/bridge/token_stream.rs @@ -85,3 +85,21 @@ impl TokenStream { result } } + +impl Extend<ExternalTokenTree> for TokenStream { + fn extend<I: IntoIterator<Item = ExternalTokenTree>>(&mut self, trees: I) { + for tt in trees { + self.push(tt.into()) + } + } +} + +impl Extend<ExternalTokenStream> for TokenStream { + fn extend<I: IntoIterator<Item = ExternalTokenStream>>(&mut self, streams: I) { + for stream in streams { + for tt in stream { + self.push(tt.into()); + } + } + } +} diff --git a/librust/proc_macro/rust/lib.rs b/librust/proc_macro/rust/lib.rs index 4888edb..31676f1 100644 --- a/librust/proc_macro/rust/lib.rs +++ b/librust/proc_macro/rust/lib.rs @@ -186,13 +186,13 @@ impl iter::FromIterator<TokenStream> for TokenStream { } impl Extend<TokenTree> for TokenStream { - fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, _trees: I) { - todo!("Implement this function") + fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, trees: I) { + self.0.extend(trees); } } impl Extend<TokenStream> for TokenStream { - fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, _streams: I) { - todo!("Implement this function") + fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) { + self.0.extend(streams) } } |