feat(build): Add CodeGenBuilder (#1154)

This commit adds a new `CodeGenBuilder` that replaces the
client/server generate fn with a builder stlye that allows
adding config items in an non-breaking way. This also deprecates
both of the client/server generate fn in favor of the builder ones.
This commit is contained in:
Lucio Franco
2022-11-28 12:10:44 -05:00
committed by GitHub
parent 542c5b37dc
commit c4525ba6ad
7 changed files with 175 additions and 38 deletions
+20
View File
@@ -9,6 +9,7 @@ use quote::{format_ident, quote};
///
/// This takes some `Service` and will generate a `TokenStream` that contains
/// a public module with the generated client.
#[deprecated(since = "0.8.3", note = "Use the CodeGenBuilder::generate_client")]
pub fn generate<T: Service>(
service: &T,
emit_package: bool,
@@ -16,6 +17,25 @@ pub fn generate<T: Service>(
compile_well_known_types: bool,
build_transport: bool,
attributes: &Attributes,
) -> TokenStream {
generate_internal(
service,
emit_package,
proto_path,
compile_well_known_types,
build_transport,
attributes,
&HashSet::default(),
)
}
pub(crate) fn generate_internal<T: Service>(
service: &T,
emit_package: bool,
proto_path: &str,
compile_well_known_types: bool,
build_transport: bool,
attributes: &Attributes,
disable_comments: &HashSet<String>,
) -> TokenStream {
let service_ident = quote::format_ident!("{}Client", service.name());