Skip to content

Commit

Permalink
Move server code generation to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
morr0ne committed Aug 15, 2024
1 parent 62c4e2b commit 0f90dfa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,21 @@ fn main() -> Result<()> {
.map(|path| quick_xml::de::from_str(&fs::read_to_string(path).unwrap()).unwrap())
.collect();

let mut generated_path = OpenOptions::new()
let mut server_path = OpenOptions::new()
.truncate(true)
.write(true)
.create(true)
.open("src/server/protocol.rs")?;

write!(&mut server_path, "{}", generate_server_code(&protocols))?;

Ok(())
}

fn generate_server_code(protocols: &[Protocol]) -> TokenStream {
let mut modules = Vec::new();

for protocol in &protocols {
for protocol in protocols {
debug!("Generating server code for \"{}\"", &protocol.name);

let mut inner_modules = Vec::new();
Expand Down Expand Up @@ -381,15 +387,11 @@ fn main() -> Result<()> {
})
}

let tokens = quote! {
quote! {
#![allow(unused)]
#![allow(async_fn_in_trait)]
#(#modules)*
};

write!(&mut generated_path, "{tokens}")?;

Ok(())
}
}

fn description_to_docs(description: Option<&String>) -> Vec<TokenStream> {
Expand Down

0 comments on commit 0f90dfa

Please sign in to comment.