1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
//
// ferogram: async Telegram MTProto client in Rust
// https://github.com/ankit-chaubey/ferogram
//
// Licensed under either the MIT License or the Apache License 2.0.
// See the LICENSE-MIT or LICENSE-APACHE file in this repository:
// https://github.com/ankit-chaubey/ferogram
//
// Feel free to use, modify, and share this code.
// Please keep this notice when redistributing.
//! Build-time code generator from a parsed TL schema to Rust source files.
//!
//! This crate is part of [ferogram](https://crates.io/crates/ferogram), an async Rust
//! MTProto client built by [Ankit Chaubey](https://github.com/ankit-chaubey).
//!
//! - Channel: [t.me/Ferogram](https://t.me/Ferogram)
//! - Chat: [t.me/FerogramChat](https://t.me/FerogramChat)
//!
//! Use this crate from a `build.rs` script to regenerate `ferogram-tl-types`
//! when you want to update to a new Telegram API layer. You feed it a parsed
//! TL schema (from `ferogram-tl-parser`) and it writes the Rust source for
//! `types`, `functions`, and `enums` modules.
//!
//! # Usage from build.rs
//!
//! ```no_run
//! use ferogram_tl_gen::{Config, Outputs, generate};
//! use ferogram_tl_parser::parse_tl_file;
//! use std::fs;
//!
//! fn main() {
//! let schema = fs::read_to_string("tl/api.tl").unwrap();
//! let defs: Vec<_> = parse_tl_file(&schema)
//! .filter_map(|r| r.ok())
//! .collect();
//!
//! let config = Config::default();
//! let mut outputs = Outputs {
//! common: Vec::new(),
//! types: Vec::new(),
//! functions: Vec::new(),
//! enums: Vec::new(),
//! };
//! generate(&defs, &config, &mut outputs).unwrap();
//!
//! let mut combined = outputs.common;
//! combined.extend(outputs.types);
//! combined.extend(outputs.functions);
//! combined.extend(outputs.enums);
//! fs::write("src/generated.rs", combined).unwrap();
//! }
//! ```
//!
//! # What it generates
//!
//! - `types` module: one `struct` per TL bare constructor, with named fields.
//! - `functions` module: one `struct` per TL function, implementing `RemoteCall`.
//! - `enums` module: one `enum` per TL boxed type, with one variant per constructor.
//!
//! All types implement `Serializable`. All enums implement `Deserializable`.
//!
//! Most users never touch this crate. It only matters when you are upgrading
//! the TL layer or maintaining a fork of `ferogram-tl-types`.
pub use ;