diff --git a/prost-build/src/code_generator.rs b/prost-build/src/code_generator.rs index 156f006dc..0c42eb4a7 100644 --- a/prost-build/src/code_generator.rs +++ b/prost-build/src/code_generator.rs @@ -253,9 +253,11 @@ impl<'a> CodeGenerator<'a> { assert_eq!(b'.', fq_message_name.as_bytes()[0]); // TODO: this clone is dirty, but expedious. if let Some(attributes) = self.config.type_attributes.get(fq_message_name).cloned() { - self.push_indent(); - self.buf.push_str(&attributes); - self.buf.push('\n'); + for attribute in attributes { + self.push_indent(); + self.buf.push_str(&attribute); + self.buf.push('\n'); + } } } @@ -268,9 +270,11 @@ impl<'a> CodeGenerator<'a> { .get_field(fq_message_name, field_name) .cloned() { - self.push_indent(); - self.buf.push_str(&attributes); - self.buf.push('\n'); + for attribute in attributes { + self.push_indent(); + self.buf.push_str(&attribute); + self.buf.push('\n'); + } } } diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index 816fd7351..34045c88d 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -224,8 +224,8 @@ pub struct Config { service_generator: Option>, map_type: PathMap, bytes_type: PathMap, - type_attributes: PathMap, - field_attributes: PathMap, + type_attributes: PathMap>, + field_attributes: PathMap>, prost_types: bool, strip_enum_prefix: bool, out_dir: Option, @@ -391,7 +391,7 @@ impl Config { A: AsRef, { self.field_attributes - .insert(path.as_ref().to_string(), attribute.as_ref().to_string()); + .extend(path.as_ref().to_string(), attribute.as_ref().to_string()); self } @@ -440,7 +440,7 @@ impl Config { A: AsRef, { self.type_attributes - .insert(path.as_ref().to_string(), attribute.as_ref().to_string()); + .extend(path.as_ref().to_string(), attribute.as_ref().to_string()); self } diff --git a/prost-build/src/path.rs b/prost-build/src/path.rs index 619d0abf0..f783761f8 100644 --- a/prost-build/src/path.rs +++ b/prost-build/src/path.rs @@ -58,6 +58,16 @@ impl PathMap { } } +impl PathMap> { + /// Inserts a new associated value to the current matchers values. + pub(crate) fn extend(&mut self, matcher: String, value: T) { + self.matchers + .entry(matcher) + .or_insert_with(|| vec![]) + .push(value); + } +} + /// Given a fully-qualified path, returns a sequence of fully-qualified paths which match a prefix /// of the input path, in decreasing path-length order. ///