ferogram_tl_types/lib.rs
1/*
2 * Copyright (c) 2026 Ankit Chaubey <ankitchaubey.dev@gmail.com>
3 * https://github.com/ankit-chaubey
4 *
5 * Project: ferogram
6 * Website: https://ferogram.dev
7 *
8 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
9 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
10 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
11 * This file may not be copied, modified, or distributed except according
12 * to those terms.
13 */
14
15#![cfg_attr(docsrs, feature(doc_cfg))]
16#![doc(html_root_url = "https://docs.rs/ferogram-tl-types/0.6.5")]
17//! Auto-generated Telegram API types, functions, and enums, regenerated from
18//! `api.tl` on every build (current layer exposed as the `LAYER` constant).
19//!
20//! This crate is part of [ferogram](https://crates.io/crates/ferogram), an async Rust
21//! MTProto client built by [Ankit Chaubey](https://github.com/ankit-chaubey).
22//!
23//! - Channel: [t.me/Ferogram](https://t.me/Ferogram)
24//! - Chat: [t.me/FerogramChat](https://t.me/FerogramChat)
25//!
26//! The entire contents are generated at build time from the TL schema in `tl/`.
27//! Do not edit the generated source by hand.
28//!
29//! Most users access this through `ferogram::tl`, which re-exports everything
30//! here. Use this crate directly only if you are building on top of the raw TL
31//! layer without the high-level `ferogram` client.
32//!
33//! # Modules
34//!
35//! | Module | Contents |
36//! |---|---|
37//! | [`types`] | Concrete constructors as `struct`s (bare types) |
38//! | [`functions`] | RPC functions as `struct`s implementing [`RemoteCall`] |
39//! | [`enums`] | Boxed types as `enum`s implementing [`Deserializable`] |
40//!
41//! # Serialization
42//!
43//! Every type in [`types`] and every function in [`functions`] implements
44//! [`Serializable`]. Every enum in [`enums`] implements [`Deserializable`].
45//!
46//! ```rust,no_run
47//! # #[cfg(feature = "tl-api")]
48//! # {
49//! use ferogram_tl_types::{functions, Serializable};
50//!
51//! let req = functions::help::GetConfig {};
52//! let bytes = req.to_bytes();
53//! // bytes is the TL-serialized wire form, ready to send over MTProto.
54//! # }
55//! ```
56//!
57//! # Feature flags
58//!
59//! | Flag | Default | Effect |
60//! |---|---|---|
61//! | `tl-api` | yes | Current-layer API schema types (`api.tl`) |
62//! | `tl-mtproto` | no | MTProto internal schema types (`mtproto.tl`, DH, transport, etc.) |
63//! | `impl-debug` | yes | `#[derive(Debug)]` on all generated types |
64//! | `impl-from-type` | yes | `From<types::T> for enums::E` |
65//! | `impl-from-enum` | yes | `TryFrom<enums::E> for types::T` |
66//! | `field-accessors` | yes | Generated getter methods for struct fields |
67//! | `deserializable-functions` | no | [`Deserializable`] on function types too |
68//! | `name-for-id` | no | `name_for_id(u32) -> Option<&'static str>` for debug printing |
69//! | `impl-serde` | no | `serde::Serialize` / `Deserialize` on generated types |
70//!
71//! # Updating to a new TL layer
72//!
73//! Replace `tl/api.tl` with the new schema and run `cargo build`.
74//! The build script regenerates all source. The `LAYER` constant reflects
75//! the current layer number.
76
77#![deny(unsafe_code)]
78#![allow(clippy::large_enum_variant)]
79
80pub mod deserialize;
81mod generated;
82pub mod serialize;
83
84pub use deserialize::{Cursor, Deserializable};
85#[cfg(feature = "name-for-id")]
86pub use generated::name_for_id;
87pub use generated::{LAYER, enums, functions, types};
88pub use serialize::Serializable;
89
90/// Bare vector: `vector` (lowercase) as opposed to the boxed `Vector`.
91///
92/// Used in rare cases where Telegram sends a length-prefixed list without
93/// the usual `0x1cb5c415` constructor ID header.
94#[derive(Clone, Debug, PartialEq)]
95#[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))]
96#[cfg_attr(feature = "impl-serde", serde(transparent))]
97pub struct RawVec<T>(pub Vec<T>);
98
99/// Opaque blob of bytes that should be passed through without interpretation.
100///
101/// Returned by functions whose response type is generic (e.g. `X`).
102#[derive(Clone, Debug, PartialEq)]
103#[cfg_attr(feature = "impl-serde", derive(serde::Serialize, serde::Deserialize))]
104#[cfg_attr(feature = "impl-serde", serde(transparent))]
105pub struct Blob(pub Vec<u8>);
106
107impl From<Vec<u8>> for Blob {
108 fn from(v: Vec<u8>) -> Self {
109 Self(v)
110 }
111}
112
113// Core traits
114
115/// Every generated type has a unique 32-bit constructor ID.
116pub trait Identifiable {
117 /// The constructor ID as specified in the TL schema.
118 const CONSTRUCTOR_ID: u32;
119}
120
121/// Marks a function type that can be sent to Telegram as an RPC call.
122///
123/// `Return` is the type Telegram will respond with.
124pub trait RemoteCall: Serializable {
125 /// The deserialized response type.
126 type Return: Deserializable;
127}