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