Skip to content

Commit

Permalink
prost-build: use parse_syn() over syn::parse_str::<syn::Arm>
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Apr 20, 2024
1 parent 95065da commit 9b28f19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions prost-build/src/code_generator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,18 @@ impl CodeGenerator<'_> {
let enum_variants = resolve_enum_variants(self, &variant_mappings, &fq_proto_enum_name);
let enum_name_syn = enum_name.parse_syn::<syn::Ident>();
let arms_1 = variant_mappings.iter().map(|variant| {
syn::parse_str::<syn::Arm>(&format!(
format!(
"{}::{} => \"{}\"",
enum_name_syn, variant.generated_variant_name, variant.proto_name
))
.expect("unable to parse enum arm")
.to_token_stream()
)
.parse_syn::<syn::Arm>()
});
let arms_2 = variant_mappings.iter().map(|variant| {
syn::parse_str::<syn::Arm>(&format!(
format!(
"\"{}\" => Some(Self::{})",
variant.proto_name, variant.generated_variant_name
))
.expect("unable to parse enum arm")
.to_token_stream()
)
.parse_syn::<syn::Arm>()
});

return Some(quote! {
Expand Down
2 changes: 1 addition & 1 deletion prost-build/src/code_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use prost_types::{
DescriptorProto, EnumDescriptorProto, FieldDescriptorProto, FieldOptions, FileDescriptorProto,
OneofDescriptorProto, ServiceDescriptorProto, SourceCodeInfo,
};
use quote::{quote, ToTokens};
use quote::quote;
use syn::{Attribute, TypePath};

use crate::ast::{Comments, Method, Service};
Expand Down

0 comments on commit 9b28f19

Please sign in to comment.