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