Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
๐ฆ layer-tl-types
Auto-generated Rust types for all Telegram API Layer 224 constructors, functions and enums.
2,329 TL constructors. Every Telegram type, function and enum โ as idiomatic Rust.
๐ฆ Installation
[]
= "0.4.5"
# With MTProto low-level types too (required by layer-mtproto):
= { = "0.4.5", = ["tl-mtproto"] }
โจ What It Does
layer-tl-types is the type system for the entire layer stack. It takes Telegram's .tl schema file (the source of truth for every type and function in the Telegram API) and, at build time, generates idiomatic Rust structs, enums, and trait implementations for all of them.
The result is a fully type-safe, zero-surprise Rust representation of 2,329 Telegram API definitions, with binary TL serialization and deserialization baked in via the Serializable and Deserializable traits.
๐ Generated Structure
// Every TL constructor becomes a Rust struct
// e.g. message#9cb490e9 id:int from_id:Peer ... = Message;
// Every abstract TL type becomes a Rust enum
// e.g. message | messageEmpty | messageService = Message
// Every TL function becomes a struct implementing RemoteCall
// e.g. messages.sendMessage#... peer:InputPeer message:string ... = Updates
๐ง Feature Flags
| Feature | Default | Description |
|---|---|---|
tl-api |
โ | Telegram API schema (api.tl) โ all high-level types |
tl-mtproto |
โ | MTProto internal schema (mtproto.tl) โ low-level protocol types |
impl-debug |
โ | #[derive(Debug)] on all generated types |
impl-from-type |
โ | From<types::T> for enums::E conversions |
impl-from-enum |
โ | TryFrom<enums::E> for types::T conversions |
deserializable-functions |
โ | Deserializable on function types (for server-side use) |
name-for-id |
โ | name_for_id(u32) -> Option<&'static str> CRC32 lookup |
impl-serde |
โ | serde::Serialize / Deserialize on all types |
๐ก Usage Examples
Serializing a TL request
use ;
let req = SendMessage ;
// Serialize to TL wire bytes (constructor ID + fields)
let bytes = req.serialize;
Deserializing a TL response
use ;
let mut cur = from_slice;
let msg = deserialize?;
match msg
Using RemoteCall for type-safe RPC
use ;
// The return type is encoded as an associated type โ no guessing, no casting
let req = GetState ;
// req: impl RemoteCall<Return = enums::updates::State>
The RemoteCall trait ties the request type to its response type at compile time, so client.invoke(&req) returns Result<R::Return, _> โ fully typed.
Type conversions
use ;
// types โ enums (From, enabled by impl-from-type feature)
let peer: Peer = PeerUser .into;
// enums โ types (TryFrom, enabled by impl-from-enum feature)
if let Ok = try_from
Name lookup (for debugging)
// Requires the `name-for-id` feature
use name_for_id;
if let Some = name_for_id
๐ Updating the TL Schema
To update to a newer Telegram API layer:
# 1. Replace the schema file
# 2. Rebuild โ code regenerates automatically
The build.rs invokes layer-tl-gen at compile time, so all types stay in sync with the schema. The cargo:rerun-if-changed instruction means only a schema change triggers regeneration, not every build.
๐ Part of the layer stack
layer-client
โโโ layer-mtproto
โโโ layer-tl-types โ you are here
โโโ (build) layer-tl-gen
โโโ (build) layer-tl-parser
๐ 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