Skip to content

Commit

Permalink
chore - codegen: Syntax to a separate file (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Apr 28, 2024
1 parent ee96a04 commit 3f2536b
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
Expand Up @@ -23,11 +23,8 @@ use crate::Config;
mod c_escaping;
use c_escaping::unescape_c_escape_string;

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

pub struct CodeGenerator<'a> {
config: &'a mut Config,
Expand Down Expand Up @@ -69,18 +66,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_deref().into(),
message_graph,
extern_paths,
depth: 0,
Expand Down
14 changes: 14 additions & 0 deletions prost-build/src/code_generator/syntax.rs
@@ -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 3f2536b

Please sign in to comment.