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

Support multiple attributes #503

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions prost-build/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand All @@ -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');
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ pub struct Config {
service_generator: Option<Box<dyn ServiceGenerator>>,
map_type: PathMap<MapType>,
bytes_type: PathMap<BytesType>,
type_attributes: PathMap<String>,
field_attributes: PathMap<String>,
type_attributes: PathMap<Vec<String>>,
field_attributes: PathMap<Vec<String>>,
prost_types: bool,
strip_enum_prefix: bool,
out_dir: Option<PathBuf>,
Expand Down Expand Up @@ -391,7 +391,7 @@ impl Config {
A: AsRef<str>,
{
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
}

Expand Down Expand Up @@ -440,7 +440,7 @@ impl Config {
A: AsRef<str>,
{
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
}

Expand Down
10 changes: 10 additions & 0 deletions prost-build/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ impl<T> PathMap<T> {
}
}

impl<T> PathMap<Vec<T>> {
/// 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.
///
Expand Down