tonic-build: support boxing fields (#1252)

This exposes https://github.com/tokio-rs/prost/pull/802 in Tonic,
though obviously until that's merged and released this diff does
nothing.

Co-authored-by: Lucio Franco <luciofranco14@gmail.com>
This commit is contained in:
Thomas Orozco
2023-04-14 18:56:14 +02:00
committed by GitHub
parent 9990e6ef9d
commit 65d909e850
+13
View File
@@ -27,6 +27,7 @@ pub fn configure() -> Builder {
message_attributes: Vec::new(),
enum_attributes: Vec::new(),
type_attributes: Vec::new(),
boxed: Vec::new(),
server_attributes: Attributes::default(),
client_attributes: Attributes::default(),
proto_path: "super".to_string(),
@@ -231,6 +232,7 @@ pub struct Builder {
pub(crate) type_attributes: Vec<(String, String)>,
pub(crate) message_attributes: Vec<(String, String)>,
pub(crate) enum_attributes: Vec<(String, String)>,
pub(crate) boxed: Vec<String>,
pub(crate) server_attributes: Attributes,
pub(crate) client_attributes: Attributes,
pub(crate) proto_path: String,
@@ -342,6 +344,14 @@ impl Builder {
self
}
/// Add additional boxed fields.
///
/// Passed directly to `prost_build::Config.boxed`.
pub fn boxed<P: AsRef<str>>(mut self, path: P) -> Self {
self.boxed.push(path.as_ref().to_string());
self
}
/// Add additional attribute to matched server `mod`s. Matches on the package name.
pub fn server_mod_attribute<P: AsRef<str>, A: AsRef<str>>(
mut self,
@@ -492,6 +502,9 @@ impl Builder {
for (prost_path, attr) in self.enum_attributes.iter() {
config.enum_attribute(prost_path, attr);
}
for prost_path in self.boxed.iter() {
config.boxed(prost_path);
}
if self.compile_well_known_types {
config.compile_well_known_types();
}