tonic_build_extend/
lib.rs

1pub trait BuilderExt {
2    fn types_attributes(self, paths: &[&str], attributes: &[&str]) -> Self;
3    fn fields_attributes(self, path: &[&str], fields: &[&str], attributes: &[&str]) -> Self;
4}
5
6impl BuilderExt for tonic_build::Builder {
7    fn types_attributes(self, paths: &[&str], attributes: &[&str]) -> Self {
8        paths.iter().fold(self, |acc, path| {
9            attributes
10                .iter()
11                .fold(acc, |acc, attribute| acc.type_attribute(path, attribute))
12        })
13    }
14
15    fn fields_attributes(self, path: &[&str], fields: &[&str], attributes: &[&str]) -> Self {
16        path.iter().fold(self, |acc, path| {
17            fields.iter().fold(acc, |acc, field| {
18                attributes.iter().fold(acc, |acc, attribute| {
19                    acc.field_attribute(format!("{}.{}", path, field), attribute)
20                })
21            })
22        })
23    }
24}