1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
// SPDX-License-Identifier: MIT OR Apache-2.0
// NOTE:
// The "Layer" project is no longer maintained or supported.
// Its original purpose for personal SDK/APK experimentation and learning
// has been fulfilled.
//
// Please use Ferogram instead:
// https://github.com/ankit-chaubey/ferogram
// Ferogram will receive future updates and development, although progress
// may be slower.
//
// Ferogram is an async Telegram MTProto client library written in Rust.
// Its implementation follows the behaviour of the official Telegram clients,
// particularly Telegram Desktop and TDLib, and aims to provide a clean and
// modern async interface for building Telegram clients and tools.
//! The [`dispatch!`] macro for pattern-matching over updates.
//!
//! Instead of writing giant `match` blocks, `dispatch!` lets you register
//! named handlers with optional guard clauses:
//!
//! ```rust,no_run
//! use layer_client::{Client, dispatch};
//! use layer_client::update::Update;
//!
//! # async fn example(client: Client, update: Update) -> Result<(), Box<dyn std::error::Error>> {
//! dispatch!(client, update,
//! NewMessage(msg) if !msg.outgoing() => {
//! println!("Got: {:?}", msg.text());
//! },
//! MessageEdited(msg) => {
//! println!("Edited: {:?}", msg.text());
//! },
//! CallbackQuery(cb) => {
//! client.answer_callback_query(cb.query_id, Some("✓"), false).await?;
//! },
//! _ => {} // catch-all for unhandled variants
//! );
//! # Ok(()) }
//! ```
//!
//! Each arm is `VariantName(binding) [if guard] => { body }`.
//! The macro expands to a plain `match` statement: zero overhead.
/// Route a [`crate::update::Update`] to the first matching arm.
///
/// # Syntax
/// ```text
/// dispatch!(client, update,
/// VariantName(binding) [if guard] => { body },
/// ...
/// [_ => { fallback }]
/// );
/// ```
///
/// - `client` : a `layer_client::Client` (available inside every arm body)
/// - `update` : the `Update` value to dispatch
/// - Each arm mirrors a variant of [`crate::update::Update`]
/// - Guards (`if expr`) are optional
/// - A catch-all `_ => {}` arm is optional but recommended to avoid warnings
/// Internal helper: do not use directly.
;
// Variant arm WITH guard
=> ;
// Variant arm WITHOUT guard
=> ;
// Trailing comma / empty: emit wildcard to ensure exhaustiveness
=> ;
}