Skip to content

Commit

Permalink
Add comment to top of generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Apr 18, 2023
1 parent b1b0185 commit 8eb883b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion generate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn write_emojis_slice<W: io::Write>(
}

fn write_phf_map<W: io::Write>(w: &mut W, map: HashMap<String, String>) -> Result<()> {
write!(w, "pub static MAP: phf::Map<&'static str, usize> = ")?;
write!(w, "pub static MAP: ::phf::Map<&'static str, usize> = ")?;
let mut gen = phf_codegen::Map::new();
for (key, value) in &map {
gen.entry(key, value);
Expand All @@ -119,6 +119,8 @@ fn write_phf_map<W: io::Write>(w: &mut W, map: HashMap<String, String>) -> Resul
Ok(())
}

const HEADER: &str = "// Code generated by `cargo run --package generate`. DO NOT EDIT.\n";

fn main() -> Result<()> {
let dir: PathBuf = [env!("CARGO_MANIFEST_DIR"), "..", "src", "gen"]
.iter()
Expand All @@ -133,6 +135,7 @@ fn main() -> Result<()> {
fs::create_dir_all(&dir)?;

let mut f = fs::File::create(dir.join("mod.rs"))?;
writeln!(f, "{}", HEADER)?;
writeln!(f, "#![cfg_attr(rustfmt, rustfmt::skip)]\n")?;
writeln!(f, "pub mod shortcode;")?;
writeln!(f, "pub mod unicode;\n")?;
Expand All @@ -149,9 +152,11 @@ fn main() -> Result<()> {
)?;

let mut f = fs::File::create(dir.join("unicode.rs"))?;
writeln!(f, "{}", HEADER)?;
write_phf_map(&mut f, unicode_map)?;

let mut f = fs::File::create(dir.join("shortcode.rs"))?;
writeln!(f, "{}", HEADER)?;
write_phf_map(&mut f, shortcode_map)?;

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/gen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Code generated by `cargo run --package generate`. DO NOT EDIT.

#![cfg_attr(rustfmt, rustfmt::skip)]

pub mod shortcode;
Expand Down
4 changes: 3 additions & 1 deletion src/gen/shortcode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub static MAP: phf::Map<&'static str, usize> = ::phf::Map {
// Code generated by `cargo run --package generate`. DO NOT EDIT.

pub static MAP: ::phf::Map<&'static str, usize> = ::phf::Map {
key: 12913932095322966823,
disps: &[
(0, 627),
Expand Down
4 changes: 3 additions & 1 deletion src/gen/unicode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub static MAP: phf::Map<&'static str, usize> = ::phf::Map {
// Code generated by `cargo run --package generate`. DO NOT EDIT.

pub static MAP: ::phf::Map<&'static str, usize> = ::phf::Map {
key: 12913932095322966823,
disps: &[
(0, 50),
Expand Down

0 comments on commit 8eb883b

Please sign in to comment.