Skip to content

Commit

Permalink
chore - codegen: Syntax to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Apr 14, 2024
1 parent e3deaa2 commit b5b26d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
15 changes: 3 additions & 12 deletions prost-build/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ use crate::ident::{strip_enum_prefix, to_snake, to_upper_camel};
use crate::message_graph::MessageGraph;
use crate::{BytesType, Config, MapType};

#[derive(PartialEq)]
enum Syntax {
Proto2,
Proto3,
}
mod syntax;
use syntax::Syntax;

pub struct CodeGenerator<'a> {
config: &'a mut Config,
Expand Down Expand Up @@ -66,18 +63,12 @@ impl<'a> CodeGenerator<'a> {
s
});

let syntax = match file.syntax.as_ref().map(String::as_str) {
None | Some("proto2") => Syntax::Proto2,
Some("proto3") => Syntax::Proto3,
Some(s) => panic!("unknown syntax: {}", s),
};

let mut code_gen = CodeGenerator {
config,
package: file.package.unwrap_or_default(),
type_path: Vec::new(),
source_info,
syntax,
syntax: file.syntax.as_ref().map(String::as_str).into(),
message_graph,
extern_paths,
depth: 0,
Expand Down
14 changes: 14 additions & 0 deletions prost-build/src/code_generator/syntax.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[derive(PartialEq)]
pub(super) enum Syntax {
Proto2,
Proto3,
}
impl From<Option<&str>> for Syntax {
fn from(optional_str: Option<&str>) -> Self {
match optional_str {
None | Some("proto2") => Syntax::Proto2,
Some("proto3") => Syntax::Proto3,
Some(s) => panic!("unknown syntax: {}", s),
}
}
}

0 comments on commit b5b26d3

Please sign in to comment.