Skip to main content

layer_tl_types/
lib.rs

1//! Generated Telegram API types, functions and enums.
2//!
3//! This crate is **auto-generated** from the TL schema files in `tl/`.
4//! To update for a new API layer, replace `tl/api.tl` and rebuild.
5//!
6//! # Overview
7//!
8//! | Module        | Contents                                                   |
9//! |---------------|------------------------------------------------------------|
10//! | [`types`]     | Concrete constructors (bare types) as `struct`s            |
11//! | [`functions`] | RPC functions as `struct`s implementing [`RemoteCall`]     |
12//! | [`enums`]     | Boxed types as `enum`s implementing [`Deserializable`]     |
13//!
14//! # Raw API usage
15//!
16//! ```rust,no_run
17//! use layer_tl_types::{functions, Serializable};
18//!
19//! let req = functions::auth::SendCode {
20//!     phone_number: "+1234567890".into(),
21//!     api_id: 12345,
22//!     api_hash: "abc".into(),
23//!     settings: Default::default(),
24//! };
25//!
26//! let bytes = req.to_bytes();
27//! // Send `bytes` over an MTProto connection…
28//! ```
29//!
30//! # Updating to a new layer
31//!
32//! 1. Replace `tl/api.tl` with the new schema.
33//! 2. `cargo build` — the build script regenerates everything.
34
35#![deny(unsafe_code)]
36#![allow(clippy::large_enum_variant)]
37
38pub mod deserialize;
39pub mod serialize;
40mod generated;
41
42pub use deserialize::{Cursor, Deserializable};
43pub use generated::{LAYER, enums, functions, types};
44#[cfg(feature = "name-for-id")]
45pub use generated::name_for_id;
46pub use serialize::Serializable;
47
48/// Bare vector — `vector` (lowercase) as opposed to the boxed `Vector`.
49///
50/// Used in rare cases where Telegram sends a length-prefixed list without
51/// the usual `0x1cb5c415` constructor ID header.
52#[derive(Clone, Debug, PartialEq)]
53pub struct RawVec<T>(pub Vec<T>);
54
55/// Opaque blob of bytes that should be passed through without interpretation.
56///
57/// Returned by functions whose response type is generic (e.g. `X`).
58#[derive(Clone, Debug, PartialEq)]
59pub struct Blob(pub Vec<u8>);
60
61impl From<Vec<u8>> for Blob {
62    fn from(v: Vec<u8>) -> Self { Self(v) }
63}
64
65// ─── Core traits ──────────────────────────────────────────────────────────────
66
67/// Every generated type has a unique 32-bit constructor ID.
68pub trait Identifiable {
69    /// The constructor ID as specified in the TL schema.
70    const CONSTRUCTOR_ID: u32;
71}
72
73/// Marks a function type that can be sent to Telegram as an RPC call.
74///
75/// `Return` is the type Telegram will respond with.
76pub trait RemoteCall: Serializable {
77    /// The deserialized response type.
78    type Return: Deserializable;
79}