public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] libproc_macro: Implement Extend for TokenStream
@ 2023-04-06 21:31 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:09c75e3750858577efe09a51416546b1e5cc0f5c

commit 09c75e3750858577efe09a51416546b1e5cc0f5c
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Mon Feb 20 13:31:52 2023 +0100

    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>

Diff:
---
 librust/proc_macro/rust/bridge/token_stream.rs | 18 ++++++++++++++++++
 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 7135a0fb81c..027f450b826 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 4888edb16a8..31676f15199 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)
     }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-06 21:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:31 [gcc/devel/rust/master] libproc_macro: Implement Extend for TokenStream Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).