[Idea or pre-RFC] Arbitrary Token Stream Region

Yes, i admit that i should make an example first, let me try to make one now. The problem the example itself exhibits is not expected to be discussed in this thread, only showing this as a potential useful mechanism. So this functionality is kind-of meta.

Example #1 Delegation

Imagine i want to help myself to write a macro to do some method forwarding(not to change Rust the language, but only to meet my own needs in my own little project), i’ve chosen the following syntax:

struct Button;
impl Button {
    fn set_text(&mut self, text: &str) {}
    fn set_state(&mut self, state: ButtonState) {}
}

struct ImageButton(Button, Image);

#[delegation]
impl ImageButton r#{
    delegate self => self.0 {
         fn set_text(&mut self, text: &str);
         fn set_state(&mut self, state: ButtonState);
    }
    fn set_image(&mut self, image:Image) {} 
}

So under the current design, this code needs to be correct parsed first before the delegation macro can process it.(I don’t know whether it will parse, let’s assume it won’t. And even if it can be parsed now, maybe it won’t be properly parsed in Rust 1.45, who knows)

Without this feature, i’ll have to modify the syntax somehow to make it more like ordinary rust, by using more attributes and reduce keyword-like structure and usages.

However, using this feature, as the r# usage within the example, the parser will magically pack whatever between these braces together, and send them to the macro. The delegation macro will reparse and generate whatever code it like to implement this functionality.