Skip to main content

ferogram_tl_types/
lib.rs

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