Skip to content

Commit

Permalink
revert breaking changes and add default
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreese committed Dec 19, 2022
1 parent ed3dac9 commit e1653f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions prost-build/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag};
use regex::Regex;

/// Comments on a Protobuf item.
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
pub struct Comments {
/// Leading detached blocks of comments.
pub leading_detached: Vec<Vec<String>>,
Expand Down Expand Up @@ -134,7 +134,7 @@ pub struct Service {
/// The package name as it appears in the .proto file.
pub package: String,
/// The service comments.
pub comments: Option<Comments>,
pub comments: Comments,
/// The service methods.
pub methods: Vec<Method>,
/// The service options.
Expand All @@ -149,7 +149,7 @@ pub struct Method {
/// The name of the method as it appears in the .proto file.
pub proto_name: String,
/// The method comments.
pub comments: Option<Comments>,
pub comments: Comments,
/// The input Rust type.
pub input_type: String,
/// The output Rust type.
Expand Down
10 changes: 8 additions & 2 deletions prost-build/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,10 @@ impl<'a> CodeGenerator<'a> {
let name = service.name().to_owned();
debug!(" service: {:?}", name);

let comments = self.location().map(Comments::from_location);
let comments = self
.location()
.map(Comments::from_location)
.unwrap_or_default();

self.path.push(2);
let methods = service
Expand All @@ -752,7 +755,10 @@ impl<'a> CodeGenerator<'a> {
debug!(" method: {:?}", method.name());

self.path.push(idx as i32);
let comments = self.location().map(Comments::from_location);
let comments = self
.location()
.map(Comments::from_location)
.unwrap_or_default();
self.path.pop();

let name = method.name.take().unwrap();
Expand Down
8 changes: 2 additions & 6 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,16 +1332,12 @@ mod tests {
impl ServiceGenerator for ServiceTraitGenerator {
fn generate(&mut self, service: Service, buf: &mut String) {
// Generate a trait for the service.
if let Some(comments) = service.comments {
comments.append_with_indent(0, buf);
}
service.comments.append_with_indent(0, buf);
buf.push_str(&format!("trait {} {{\n", &service.name));

// Generate the service methods.
for method in service.methods {
if let Some(comments) = method.comments {
comments.append_with_indent(1, buf);
}
method.comments.append_with_indent(1, buf);
buf.push_str(&format!(
" fn {}(_: {}) -> {};\n",
method.name, method.input_type, method.output_type
Expand Down

0 comments on commit e1653f5

Please sign in to comment.