commure / sourcegen

🐠Like procedural macro, but generates sources! 🐡
Apache License 2.0
30 stars 4 forks source link

🦇Figure out the story for generating multiple items #4

Closed idubrov closed 5 years ago

idubrov commented 5 years ago

Sometimes it could be beneficial to let the sourcegen to generate multiple items:

#[sourcegen::sourcegen(generator = "friendly")]
struct Hello {}

// Also handled by sourcegen!
impl std::fmt::Display for Hello {}

However, it is not clear how to detect the end bound of the range to replace?

idubrov commented 5 years ago

One option is to use a comment marker indicating beginning and end of the generated code instead of relying on item range. Like:

// -- BEGIN GENERATED CODE -- 
code...
// -- END GENERATED CODE --
idubrov commented 5 years ago

Another suggestion is to use another marker attribute:

#[sourcegen::sourcegen(..)]
struct Boo;

#[sourcegen::generated]
impl Boo {
}

And make the toolkit to consume all consecutive items with #[sourcegen::generated]. Not clear if we should also give them back to the generator (would require changing its API). Initially, I think, it would be fine to only give the "primary" item, but replace all of them.

idubrov commented 5 years ago

Fixed via #8