⚙️ layer-tl-gen
Build-time Rust code generator for Telegram's TL schema.
From TL AST to idiomatic Rust structs, enums, and traits — automatically.
📦 Installation
[]
= "0.1.1"
✨ What It Does
layer-tl-gen takes a parsed TL AST (from layer-tl-parser) and generates complete, idiomatic Rust source code — structs for constructors, enums for abstract types, and trait implementations for functions.
It runs at build time via build.rs, so the generated code is always in sync with the schema — no manual updates needed.
🏗️ What Gets Generated
For every TL definition in the schema, layer-tl-gen produces:
Constructor → Rust struct
peerUser#9db1bc6d user_id:long = Peer;
// generated in types module
Abstract type → Rust enum
peerUser = Peer;
peerChat = Peer;
peerChannel = Peer;
// generated in enums module
// dispatches on CRC32 id
Function → RemoteCall impl
messages.sendMessage#... peer:InputPeer message:string ... = Updates;
// generated in functions::messages module
💡 Usage in build.rs
// layer-tl-types/build.rs
use generate;
⚙️ Config Options
🔗 Part of the layer stack
layer-tl-types (consumes the generated code)
└── layer-tl-gen ← you are here (generates at build time)
└── layer-tl-parser (parses the .tl schema)
📄 License
Licensed under either of, at your option:
- MIT License — see LICENSE-MIT
- Apache License, Version 2.0 — see LICENSE-APACHE
👤 Author
Ankit Chaubey github.com/ankit-chaubey · ankitchaubey.in · ankitchaubey.dev@gmail.com