Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up CodeGenerator by moving compilation-global data and logic to Context #1190

Merged
merged 8 commits into from
Feb 7, 2025
Prev Previous commit
Next Next commit
refactor: rename Context::service_generator
Rename to service_generator_mut so it's evident that we are obtaining
a mutable reference even though the Context reference is shared.
  • Loading branch information
mzabaluev committed Jan 19, 2025
commit 01854ba4a5cb10c2ec65ba185c490cb47369de08
6 changes: 3 additions & 3 deletions prost-build/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ impl<'a, 'b> CodeGenerator<'a, 'b> {
}
code_gen.path.pop();

if code_gen.context.service_generator().is_some() {
if code_gen.context.service_generator_mut().is_some() {
code_gen.path.push(6);
for (idx, service) in file.service.into_iter().enumerate() {
code_gen.path.push(idx as i32);
code_gen.push_service(service);
code_gen.path.pop();
}

if let Some(service_generator) = code_gen.context.service_generator() {
if let Some(service_generator) = code_gen.context.service_generator_mut() {
service_generator.finalize(code_gen.buf);
}

Expand Down Expand Up @@ -885,7 +885,7 @@ impl<'a, 'b> CodeGenerator<'a, 'b> {
options: service.options.unwrap_or_default(),
};

if let Some(service_generator) = self.context.service_generator() {
if let Some(service_generator) = self.context.service_generator_mut() {
service_generator.generate(service, self.buf)
}
}
Expand Down
2 changes: 1 addition & 1 deletion prost-build/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ impl Config {
}
}

if let Some(service_generator) = context.service_generator() {
if let Some(service_generator) = context.service_generator_mut() {
for (module, package) in packages {
let buf = modules.get_mut(&module).unwrap();
service_generator.finalize_package(&package, buf);
Expand Down
2 changes: 1 addition & 1 deletion prost-build/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> Context<'a> {
self.config
}

pub fn service_generator(&mut self) -> Option<&mut (dyn ServiceGenerator + 'static)> {
pub fn service_generator_mut(&mut self) -> Option<&mut (dyn ServiceGenerator + 'static)> {
self.config.service_generator.as_deref_mut()
}

Expand Down