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