Skip to main content

layer_tl_types/
lib.rs

1// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4// NOTE:
5// The "Layer" project is no longer maintained or supported.
6// Its original purpose for personal SDK/APK experimentation and learning
7// has been fulfilled.
8//
9// Please use Ferogram instead:
10// https://github.com/ankit-chaubey/ferogram
11// Ferogram will receive future updates and development, although progress
12// may be slower.
13//
14// Ferogram is an async Telegram MTProto client library written in Rust.
15// Its implementation follows the behaviour of the official Telegram clients,
16// particularly Telegram Desktop and TDLib, and aims to provide a clean and
17// modern async interface for building Telegram clients and tools.
18
19#![cfg_attr(docsrs, feature(doc_cfg))]
20#![doc(html_root_url = "https://docs.rs/layer-tl-types/0.5.0")]
21//! Generated Telegram API types, functions and enums.
22//!
23//! This crate is **auto-generated** from the TL schema files in `tl/`.
24//! To update for a new API layer, replace `tl/api.tl` and rebuild.
25//!
26//! # Overview
27//!
28//! | Module        | Contents                                                   |
29//! |---------------|------------------------------------------------------------|
30//! | [`types`]     | Concrete constructors (bare types) as `struct`s            |
31//! | [`functions`] | RPC functions as `struct`s implementing [`RemoteCall`]     |
32//! | [`enums`]     | Boxed types as `enum`s implementing [`Deserializable`]     |
33//!
34//! # Raw API usage
35//!
36//! ```rust,no_run
37//! use layer_tl_types::{functions, Serializable};
38//!
39//! let req = functions::auth::SendCode {
40//! phone_number: "+1234567890".into(),
41//! api_id: 12345,
42//! api_hash: "abc".into(),
43//! settings: Default::default(),
44//! };
45//!
46//! let bytes = req.to_bytes();
47//! // Send `bytes` over an MTProto connection…
48//! ```
49//!
50//! # Updating to a new layer
51//!
52//! 1. Replace `tl/api.tl` with the new schema.
53//! 2. `cargo build`: the build script regenerates everything.
54
55#![deny(unsafe_code)]
56#![allow(clippy::large_enum_variant)]
57
58pub mod deserialize;
59mod generated;
60pub mod serialize;
61
62pub use deserialize::{Cursor, Deserializable};
63#[cfg(feature = "name-for-id")]
64pub use generated::name_for_id;
65pub use generated::{LAYER, enums, functions, types};
66pub use serialize::Serializable;
67
68/// Bare vector: `vector` (lowercase) as opposed to the boxed `Vector`.
69///
70/// Used in rare cases where Telegram sends a length-prefixed list without
71/// the usual `0x1cb5c415` constructor ID header.
72#[derive(Clone, Debug, PartialEq)]
73pub struct RawVec<T>(pub Vec<T>);
74
75/// Opaque blob of bytes that should be passed through without interpretation.
76///
77/// Returned by functions whose response type is generic (e.g. `X`).
78#[derive(Clone, Debug, PartialEq)]
79pub struct Blob(pub Vec<u8>);
80
81impl From<Vec<u8>> for Blob {
82    fn from(v: Vec<u8>) -> Self {
83        Self(v)
84    }
85}
86
87// Core traits
88
89/// Every generated type has a unique 32-bit constructor ID.
90pub trait Identifiable {
91    /// The constructor ID as specified in the TL schema.
92    const CONSTRUCTOR_ID: u32;
93}
94
95/// Marks a function type that can be sent to Telegram as an RPC call.
96///
97/// `Return` is the type Telegram will respond with.
98pub trait RemoteCall: Serializable {
99    /// The deserialized response type.
100    type Return: Deserializable;
101}