Expand description
Build-time code generator from a parsed TL schema to Rust source files.
This crate is part of ferogram, an async Rust MTProto client built by Ankit Chaubey.
- Channel: t.me/Ferogram
- Chat: 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
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
typesmodule: onestructper TL bare constructor, with named fields.functionsmodule: onestructper TL function, implementingRemoteCall.enumsmodule: oneenumper 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.
Structs§
Functions§
- generate
- Generate Rust source code from a slice of parsed TL definitions.