1mod enums;
14mod functions;
15mod metadata;
16mod rustifier;
17mod types;
18
19use std::io::{self, Write};
20use tdlib_rs_parser::tl::{Definition, Type};
21
22const SPECIAL_CASED_TYPES: [&str; 6] = ["Bool", "Bytes", "Int32", "Int53", "Int64", "Ok"];
25
26fn ignore_type(ty: &Type) -> bool {
27 SPECIAL_CASED_TYPES.iter().any(|&x| x == ty.name)
28}
29
30pub fn generate_rust_code(
31 file: &mut impl Write,
32 definitions: &[Definition],
33 gen_bots_only_api: bool,
34) -> io::Result<()> {
35 write!(
36 file,
37 "\
38 // Copyright 2020 - developers of the `grammers` project.\n\
39 // Copyright 2021 - developers of the `tdlib-rs` project.\n\
40 // Copyright 2024 - developers of the `tgt` and `tdlib-rs` projects.\n\
41 //\n\
42 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or\n\
43 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n\
44 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your\n\
45 // option. This file may not be copied, modified, or distributed\n\
46 // except according to those terms.\n\
47 "
48 )?;
49
50 let metadata = metadata::Metadata::new(definitions);
51 types::write_types_mod(file, definitions, &metadata, gen_bots_only_api)?;
52 enums::write_enums_mod(file, definitions, &metadata, gen_bots_only_api)?;
53 functions::write_functions_mod(file, definitions, &metadata, gen_bots_only_api)?;
54
55 Ok(())
56}