udoprog / genco

A whitespace-aware quasiquoter for beautiful code generation.
Apache License 2.0
181 stars 11 forks source link

[Rust] Support #![] module level attributes #36

Open rrichardson opened 1 year ago

rrichardson commented 1 year ago

When attempting to put #![allow(clippy)] at the top of a file, it gets placed below any imports created by register.

It'd be nice to specify, perhaps in the Rust config, any top-of-module lines that must be present.

The workaround is to just insert such things first at the top of a file, but this sort of breaks the abstraction.

udoprog commented 1 year ago

Hah, for sure! Maybe the import location should be specified explicitly or something like it.

millergarym commented 1 year ago

Hah, for sure! Maybe the import location should be specified explicitly or something like it.

Another option would be for an explicit header similar to rust::import (lang::import) but for headers. This feature could also be used for comments.

e.g.

let header = rust::header("/* generated code using the assume genco library */");
let clippy = rust::header("#![allow(clippy)]");
let tokens = quote{ $(register( (header, clippy) );
...
};