mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
commit
716f3c131d
18 changed files with 47 additions and 47 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -19,7 +19,7 @@ env:
|
||||||
# When updating this, also update:
|
# When updating this, also update:
|
||||||
# - crates/teloxide-core/src/codegen.rs
|
# - crates/teloxide-core/src/codegen.rs
|
||||||
# - rust-toolchain.toml
|
# - rust-toolchain.toml
|
||||||
rust_nightly: nightly-2023-05-28
|
rust_nightly: nightly-2023-09-27
|
||||||
# When updating this, also update:
|
# When updating this, also update:
|
||||||
# - **/README.md
|
# - **/README.md
|
||||||
# - **/src/lib.rs
|
# - **/src/lib.rs
|
||||||
|
@ -84,7 +84,7 @@ jobs:
|
||||||
toolchain: beta
|
toolchain: beta
|
||||||
features: "--features full"
|
features: "--features full"
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
toolchain: nightly-2023-05-28
|
toolchain: nightly-2023-09-27
|
||||||
features: "--features full nightly"
|
features: "--features full nightly"
|
||||||
- rust: msrv
|
- rust: msrv
|
||||||
toolchain: 1.65.0
|
toolchain: 1.65.0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
# The settings below will be applied to all crates in the workspace
|
# The settings below will be applied to all crates in the workspace
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
|
|
|
@ -155,18 +155,18 @@ pub(super) async fn worker<B>(
|
||||||
//
|
//
|
||||||
// Reasons (not to use `spawn_blocking`):
|
// Reasons (not to use `spawn_blocking`):
|
||||||
//
|
//
|
||||||
// 1. The work seems not very CPU-bound, it's not heavy computations,
|
// 1. The work seems not very CPU-bound, it's not heavy computations, it's more
|
||||||
// it's more like light computations.
|
// like light computations.
|
||||||
//
|
//
|
||||||
// 2. `spawn_blocking` is not zero-cost — it spawns a new system thread
|
// 2. `spawn_blocking` is not zero-cost — it spawns a new system thread
|
||||||
// + do so other work. This may actually be *worse* then current
|
// + do so other work. This may actually be *worse* then current
|
||||||
// "just do everything in this async fn" approach.
|
// "just do everything in this async fn" approach.
|
||||||
//
|
//
|
||||||
// 3. With `rt-threaded` feature, tokio uses [`num_cpus()`] threads
|
// 3. With `rt-threaded` feature, tokio uses [`num_cpus()`] threads which should
|
||||||
// which should be enough to work fine with one a-bit-blocking task.
|
// be enough to work fine with one a-bit-blocking task. Crucially current
|
||||||
// Crucially current behaviour will be problem mostly with
|
// behaviour will be problem mostly with single-threaded runtimes (and in
|
||||||
// single-threaded runtimes (and in case you're using one, you
|
// case you're using one, you probably don't want to spawn unnecessary
|
||||||
// probably don't want to spawn unnecessary threads anyway).
|
// threads anyway).
|
||||||
//
|
//
|
||||||
// I think if we'll ever change this behaviour, we need to make it
|
// I think if we'll ever change this behaviour, we need to make it
|
||||||
// _configurable_.
|
// _configurable_.
|
||||||
|
|
|
@ -23,7 +23,7 @@ use xshell::{cmd, Shell};
|
||||||
|
|
||||||
fn ensure_rustfmt(sh: &Shell) {
|
fn ensure_rustfmt(sh: &Shell) {
|
||||||
// FIXME(waffle): find a better way to set toolchain
|
// FIXME(waffle): find a better way to set toolchain
|
||||||
let toolchain = "nightly-2023-05-28";
|
let toolchain = "nightly-2023-09-27";
|
||||||
|
|
||||||
let version = cmd!(sh, "rustup run {toolchain} rustfmt --version").read().unwrap_or_default();
|
let version = cmd!(sh, "rustup run {toolchain} rustfmt --version").read().unwrap_or_default();
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ fn ensure_rustfmt(sh: &Shell) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reformat(text: String) -> String {
|
pub fn reformat(text: String) -> String {
|
||||||
let toolchain = "nightly-2023-05-28";
|
let toolchain = "nightly-2023-09-27";
|
||||||
|
|
||||||
let sh = Shell::new().unwrap();
|
let sh = Shell::new().unwrap();
|
||||||
ensure_rustfmt(&sh);
|
ensure_rustfmt(&sh);
|
||||||
|
|
|
@ -1333,6 +1333,8 @@ macro_rules! requester_forward {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
// waffle: efficiency is not important here, and I don't want to rewrite this
|
||||||
|
#[allow(clippy::format_collect)]
|
||||||
fn codegen_requester_forward() {
|
fn codegen_requester_forward() {
|
||||||
use crate::codegen::{
|
use crate::codegen::{
|
||||||
add_hidden_preamble,
|
add_hidden_preamble,
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
// waffle: efficiency is not important here, and I don't want to rewrite this
|
||||||
|
#![allow(clippy::format_collect)]
|
||||||
|
|
||||||
use std::{borrow::Borrow, collections::HashSet, ops::Deref};
|
use std::{borrow::Borrow, collections::HashSet, ops::Deref};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -51,7 +54,7 @@ fn codegen_payloads() {
|
||||||
|
|
||||||
let multipart = multipart_input_file_fields(&method)
|
let multipart = multipart_input_file_fields(&method)
|
||||||
.map(|field| format!(" @[multipart = {}]\n", field.join(", ")))
|
.map(|field| format!(" @[multipart = {}]\n", field.join(", ")))
|
||||||
.unwrap_or_else(String::new);
|
.unwrap_or_default();
|
||||||
|
|
||||||
let derive = if !multipart.is_empty()
|
let derive = if !multipart.is_empty()
|
||||||
|| matches!(
|
|| matches!(
|
||||||
|
|
|
@ -1337,6 +1337,8 @@ where
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
// waffle: efficiency is not important here, and I don't want to rewrite this
|
||||||
|
#[allow(clippy::format_collect)]
|
||||||
fn codegen_requester_methods() {
|
fn codegen_requester_methods() {
|
||||||
use crate::codegen::{
|
use crate::codegen::{
|
||||||
add_hidden_preamble,
|
add_hidden_preamble,
|
||||||
|
|
|
@ -315,7 +315,7 @@ pub(crate) mod serde_opt_date_from_unix_timestamp {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let json = r#"{}"#;
|
let json = "{}";
|
||||||
|
|
||||||
let Struct { date } = serde_json::from_str(json).unwrap();
|
let Struct { date } = serde_json::from_str(json).unwrap();
|
||||||
assert_eq!(date, None);
|
assert_eq!(date, None);
|
||||||
|
|
|
@ -203,8 +203,8 @@ impl PassportElementErrorReverseSide {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Represents an issue with the selfie with a document.
|
/// Represents an issue with the selfie with a document.
|
||||||
//
|
///
|
||||||
/// The error is considered resolved when the file with the selfie changes.
|
/// The error is considered resolved when the file with the selfie changes.
|
||||||
///
|
///
|
||||||
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorselfie).
|
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorselfie).
|
||||||
|
|
|
@ -31,7 +31,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chat_id_id_serialization() {
|
fn chat_id_id_serialization() {
|
||||||
let expected_json = String::from(r#"123456"#);
|
let expected_json = String::from("123456");
|
||||||
let actual_json = serde_json::to_string(&Recipient::Id(ChatId(123_456))).unwrap();
|
let actual_json = serde_json::to_string(&Recipient::Id(ChatId(123_456))).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_json, actual_json)
|
assert_eq!(expected_json, actual_json)
|
||||||
|
|
|
@ -66,7 +66,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn smoke_deser() {
|
fn smoke_deser() {
|
||||||
let json = r#"123"#;
|
let json = "123";
|
||||||
let mid: ThreadId = serde_json::from_str(json).unwrap();
|
let mid: ThreadId = serde_json::from_str(json).unwrap();
|
||||||
assert_eq!(mid, ThreadId(MessageId(123)));
|
assert_eq!(mid, ThreadId(MessageId(123)));
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,6 @@ mod tests {
|
||||||
fn smoke_ser() {
|
fn smoke_ser() {
|
||||||
let mid: ThreadId = ThreadId(MessageId(123));
|
let mid: ThreadId = ThreadId(MessageId(123));
|
||||||
let json = serde_json::to_string(&mid).unwrap();
|
let json = serde_json::to_string(&mid).unwrap();
|
||||||
assert_eq!(json, r#"123"#);
|
assert_eq!(json, "123");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@ proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = "1.0.7"
|
quote = "1.0.7"
|
||||||
proc-macro2 = "1.0.19"
|
proc-macro2 = "1.0.67"
|
||||||
syn = { version = "1.0.13", features = ["full"] }
|
syn = { version = "1.0.13", features = ["full"] }
|
||||||
heck = "0.4.0"
|
heck = "0.4.0"
|
||||||
|
|
||||||
[package.metadata.release]
|
[package.metadata.release]
|
||||||
tag-prefix = "macros-"
|
tag-prefix = "macros-"
|
||||||
pre-release-replacements = [
|
pre-release-replacements = [
|
||||||
{file="CHANGELOG.md", search="## unreleased", replace="## unreleased\n\n## {{version}} - {{date}}", exactly=1},
|
{ file = "CHANGELOG.md", search = "## unreleased", replace = "## unreleased\n\n## {{version}} - {{date}}", exactly = 1 },
|
||||||
]
|
]
|
||||||
|
|
|
@ -19,10 +19,7 @@ pub(crate) fn fold_attrs<A, R>(
|
||||||
.filter(|&a| filter(a))
|
.filter(|&a| filter(a))
|
||||||
.flat_map(|attribute| {
|
.flat_map(|attribute| {
|
||||||
let Some(key) = attribute.path.get_ident().cloned() else {
|
let Some(key) = attribute.path.get_ident().cloned() else {
|
||||||
return vec![Err(compile_error_at(
|
return vec![Err(compile_error_at("expected an ident", attribute.path.span()))];
|
||||||
"expected an ident",
|
|
||||||
attribute.path.span(),
|
|
||||||
))];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match (|input: ParseStream<'_>| Attrs::parse_with_key(input, key))
|
match (|input: ParseStream<'_>| Attrs::parse_with_key(input, key))
|
||||||
|
|
|
@ -145,13 +145,12 @@ impl CommandAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
"command" => {
|
"command" => {
|
||||||
let Some(attr) = key.pop()
|
let Some(attr) = key.pop() else {
|
||||||
else {
|
return Err(compile_error_at(
|
||||||
return Err(compile_error_at(
|
"expected an attribute name",
|
||||||
"expected an attribute name",
|
outermost_key.span(),
|
||||||
outermost_key.span(),
|
));
|
||||||
))
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(unexpected_key) = key.last() {
|
if let Some(unexpected_key) = key.last() {
|
||||||
return Err(compile_error_at(
|
return Err(compile_error_at(
|
||||||
|
|
|
@ -42,12 +42,12 @@ impl<S> SqliteStorage<S> {
|
||||||
let pool = SqlitePool::connect(format!("sqlite:{path}?mode=rwc").as_str()).await?;
|
let pool = SqlitePool::connect(format!("sqlite:{path}?mode=rwc").as_str()).await?;
|
||||||
let mut conn = pool.acquire().await?;
|
let mut conn = pool.acquire().await?;
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
r#"
|
"
|
||||||
CREATE TABLE IF NOT EXISTS teloxide_dialogues (
|
CREATE TABLE IF NOT EXISTS teloxide_dialogues (
|
||||||
chat_id BIGINT PRIMARY KEY,
|
chat_id BIGINT PRIMARY KEY,
|
||||||
dialogue BLOB NOT NULL
|
dialogue BLOB NOT NULL
|
||||||
);
|
);
|
||||||
"#,
|
",
|
||||||
)
|
)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -98,10 +98,10 @@ where
|
||||||
.await?
|
.await?
|
||||||
.execute(
|
.execute(
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
r#"
|
"
|
||||||
INSERT INTO teloxide_dialogues VALUES (?, ?)
|
INSERT INTO teloxide_dialogues VALUES (?, ?)
|
||||||
ON CONFLICT(chat_id) DO UPDATE SET dialogue=excluded.dialogue
|
ON CONFLICT(chat_id) DO UPDATE SET dialogue=excluded.dialogue
|
||||||
"#,
|
",
|
||||||
)
|
)
|
||||||
.bind(chat_id)
|
.bind(chat_id)
|
||||||
.bind(d),
|
.bind(d),
|
||||||
|
|
|
@ -165,9 +165,9 @@ where
|
||||||
/// the [`Requester`] trait.
|
/// the [`Requester`] trait.
|
||||||
/// 2. `handler` is an `async` function that takes arguments from
|
/// 2. `handler` is an `async` function that takes arguments from
|
||||||
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
||||||
/// 3. `cmd` is a type hint for your command enumeration
|
/// 3. `cmd` is a type hint for your command enumeration `MyCommand`: just write
|
||||||
/// `MyCommand`: just write `MyCommand::ty()`. Note that `MyCommand` must
|
/// `MyCommand::ty()`. Note that `MyCommand` must implement the
|
||||||
/// implement the [`BotCommands`] trait, typically via
|
/// [`BotCommands`] trait, typically via
|
||||||
/// `#[derive(BotCommands)]`.
|
/// `#[derive(BotCommands)]`.
|
||||||
///
|
///
|
||||||
/// All the other requirements are about thread safety and data validity and can
|
/// All the other requirements are about thread safety and data validity and can
|
||||||
|
@ -236,8 +236,8 @@ where
|
||||||
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
||||||
/// 3. `listener` is something that takes updates from a Telegram server and
|
/// 3. `listener` is something that takes updates from a Telegram server and
|
||||||
/// implements [`UpdateListener`].
|
/// implements [`UpdateListener`].
|
||||||
/// 4. `cmd` is a type hint for your command enumeration `MyCommand`: just
|
/// 4. `cmd` is a type hint for your command enumeration `MyCommand`: just write
|
||||||
/// write `MyCommand::ty()`. Note that `MyCommand` must implement the
|
/// `MyCommand::ty()`. Note that `MyCommand` must implement the
|
||||||
/// [`BotCommands`] trait, typically via `#[derive(BotCommands)]`.
|
/// [`BotCommands`] trait, typically via `#[derive(BotCommands)]`.
|
||||||
///
|
///
|
||||||
/// All the other requirements are about thread safety and data validity and can
|
/// All the other requirements are about thread safety and data validity and can
|
||||||
|
|
|
@ -283,9 +283,6 @@ mod tests {
|
||||||
is_premium: false,
|
is_premium: false,
|
||||||
added_to_attachment_menu: false,
|
added_to_attachment_menu: false,
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(user_mention_or_link(&user_without_username), "[Name](tg://user/?id=123456789)")
|
||||||
user_mention_or_link(&user_without_username),
|
|
||||||
r#"[Name](tg://user/?id=123456789)"#
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly-2023-05-28"
|
channel = "nightly-2023-09-27"
|
||||||
components = ["rustfmt", "clippy"]
|
components = ["rustfmt", "clippy"]
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
|
|
Loading…
Reference in a new issue