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
+18
View File
@@ -10,12 +10,30 @@ use syn::{Ident, Lit, LitStr};
///
/// This takes some `Service` and will generate a `TokenStream` that contains
/// a public module containing the server service and handler trait.
#[deprecated(since = "0.8.3", note = "Use CodeGenBuilder::generate_server")]
pub fn generate<T: Service>(
service: &T,
emit_package: bool,
proto_path: &str,
compile_well_known_types: bool,
attributes: &Attributes,
) -> TokenStream {
generate_internal(
service,
emit_package,
proto_path,
compile_well_known_types,
attributes,
&HashSet::default(),
)
}
pub(crate) fn generate_internal<T: Service>(
service: &T,
emit_package: bool,
proto_path: &str,
compile_well_known_types: bool,
attributes: &Attributes,
disable_comments: &HashSet<String>,
) -> TokenStream {
let methods = generate_methods(service, proto_path, compile_well_known_types);