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