From b66f1a05ef5bd8d19686fb73f5fb92967903d482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Westlin?= Date: Mon, 11 Mar 2024 18:16:41 +0100 Subject: [PATCH] Fix handling of filename for keywords --- proto-gen/src/gen.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/proto-gen/src/gen.rs b/proto-gen/src/gen.rs index fc6979d..f1f94dd 100644 --- a/proto-gen/src/gen.rs +++ b/proto-gen/src/gen.rs @@ -216,7 +216,9 @@ impl Module { Some(output) }; if let Some(file) = self.file.as_ref() { - let file_location = self.location.join(format!("{}.rs", self.name)); + let file_location = self + .location + .join(format!("{}.rs", self.proper_file_name())); // It's the same filename we don't need to move it but we need to edit it if it has // child modules. let is_same_file = &file_location == file; @@ -261,6 +263,15 @@ impl Module { fn get_name(&self) -> &str { self.name.as_str() } + + #[inline] + fn proper_file_name<'a>(&self) -> &str { + if self.name.starts_with("r#") { + &self.name[2..] + } else { + self.name.as_str() + } + } } fn as_file_name_string(path: impl AsRef) -> Result {