From 65d909e85050e0cbbf50455e0b3531a0d08eff8d Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Fri, 14 Apr 2023 18:56:14 +0200 Subject: [PATCH] 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 --- tonic-build/src/prost.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tonic-build/src/prost.rs b/tonic-build/src/prost.rs index 978533cc8..2b363133d 100644 --- a/tonic-build/src/prost.rs +++ b/tonic-build/src/prost.rs @@ -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, 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>(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, A: AsRef>( 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(); }