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