mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Fix assorted warnings
This commit is contained in:
parent
cedf223b0d
commit
b8c45110a3
28 changed files with 50 additions and 99 deletions
|
@ -12,7 +12,7 @@ use url::Url;
|
||||||
use crate::{
|
use crate::{
|
||||||
payloads::GetMe,
|
payloads::GetMe,
|
||||||
requests::{HasPayload, Request, Requester},
|
requests::{HasPayload, Request, Requester},
|
||||||
types::{Me, Recipient, *},
|
types::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// `get_me` cache.
|
/// `get_me` cache.
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
prelude::Requester,
|
prelude::Requester,
|
||||||
requests::{HasPayload, Output, Request},
|
requests::{HasPayload, Output, Request},
|
||||||
types::{InputFile, ParseMode, Recipient, *},
|
types::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Default parse mode adaptor, see
|
/// Default parse mode adaptor, see
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
html_logo_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png",
|
html_logo_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png",
|
||||||
html_favicon_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png"
|
html_favicon_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png"
|
||||||
)]
|
)]
|
||||||
#![forbid(unsafe_code)]
|
//
|
||||||
// we pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.`
|
// we pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.`
|
||||||
//
|
//
|
||||||
// To properly build docs of this crate run
|
// To properly build docs of this crate run
|
||||||
|
@ -78,16 +78,29 @@
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
|
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
|
||||||
#![cfg_attr(all(feature = "full", docsrs), deny(rustdoc::broken_intra_doc_links))]
|
#![cfg_attr(all(feature = "full", docsrs), deny(rustdoc::broken_intra_doc_links))]
|
||||||
|
//
|
||||||
|
// Lint levels
|
||||||
|
#![forbid(unsafe_code)]
|
||||||
//#![deny(missing_docs)]
|
//#![deny(missing_docs)]
|
||||||
#![warn(clippy::print_stdout, clippy::dbg_macro)]
|
#![warn(clippy::print_stdout, clippy::dbg_macro)]
|
||||||
#![allow(clippy::let_and_return)]
|
|
||||||
#![allow(clippy::bool_assert_comparison)]
|
|
||||||
// Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
|
|
||||||
#![allow(clippy::return_self_not_must_use)]
|
|
||||||
// Workaround for CI
|
|
||||||
#![allow(rustdoc::bare_urls)]
|
|
||||||
// FIXME: deal with these lints
|
|
||||||
#![allow(
|
#![allow(
|
||||||
|
// Sometimes it's more readable to assign to a variable and return it immediately
|
||||||
|
clippy::let_and_return,
|
||||||
|
|
||||||
|
// When you are testing ->bool functions, it makes sense to `assert_eq!(f(..), false)`
|
||||||
|
clippy::bool_assert_comparison,
|
||||||
|
|
||||||
|
// Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
|
||||||
|
clippy::return_self_not_must_use,
|
||||||
|
|
||||||
|
// This is dumb. `T: ?Sized where T: Trait` IMO makes perfect sense
|
||||||
|
clippy::multiple_bound_locations,
|
||||||
|
|
||||||
|
// Workaround for CI
|
||||||
|
// FIXME: do we still need this?
|
||||||
|
rustdoc::bare_urls,
|
||||||
|
|
||||||
|
// FIXME: deal with these lints
|
||||||
clippy::collapsible_str_replace,
|
clippy::collapsible_str_replace,
|
||||||
clippy::borrow_deref_ref,
|
clippy::borrow_deref_ref,
|
||||||
clippy::unnecessary_lazy_evaluations,
|
clippy::unnecessary_lazy_evaluations,
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl<R> From<TelegramResponse<R>> for ResponseResult<R> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{errors::ApiError, types::Update};
|
use crate::types::Update;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_terminated_by_other_get_updates() {
|
fn parse_terminated_by_other_get_updates() {
|
||||||
|
|
|
@ -20,4 +20,3 @@ mod payload;
|
||||||
mod request;
|
mod request;
|
||||||
mod requester;
|
mod requester;
|
||||||
mod requester_ext;
|
mod requester_ext;
|
||||||
mod utils;
|
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{payloads::*, requests::Request, types::*};
|
||||||
payloads::{GetMe, SendMessage, *},
|
|
||||||
requests::Request,
|
|
||||||
types::*,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Telegram Bot API client.
|
/// Telegram Bot API client.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
use bytes::{Bytes, BytesMut};
|
|
||||||
use tokio_util::codec::Decoder;
|
|
||||||
|
|
||||||
struct FileDecoder;
|
|
||||||
|
|
||||||
impl Decoder for FileDecoder {
|
|
||||||
type Item = Bytes;
|
|
||||||
type Error = std::io::Error;
|
|
||||||
|
|
||||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
|
||||||
if src.is_empty() {
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
Ok(Some(src.split().freeze()))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -268,16 +268,12 @@ pub use user_id::*;
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
/// Converts an `i64` timestump to a `choro::DateTime`, producing serde error
|
/// Converts an `i64` timestamp to a `choro::DateTime`, producing serde error
|
||||||
/// for invalid timestumps
|
/// for invalid timestamps
|
||||||
pub(crate) fn serde_timestamp<E: serde::de::Error>(
|
pub(crate) fn serde_timestamp<E: serde::de::Error>(
|
||||||
timestamp: i64,
|
timestamp: i64,
|
||||||
) -> Result<chrono::DateTime<chrono::Utc>, E> {
|
) -> Result<chrono::DateTime<chrono::Utc>, E> {
|
||||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
chrono::DateTime::from_timestamp(timestamp, 0).ok_or_else(|| E::custom("invalid timestump"))
|
||||||
|
|
||||||
NaiveDateTime::from_timestamp_opt(timestamp, 0)
|
|
||||||
.ok_or_else(|| E::custom("invalid timestump"))
|
|
||||||
.map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod serde_opt_date_from_unix_timestamp {
|
pub(crate) mod serde_opt_date_from_unix_timestamp {
|
||||||
|
@ -313,10 +309,7 @@ pub(crate) mod serde_opt_date_from_unix_timestamp {
|
||||||
|
|
||||||
{
|
{
|
||||||
let json = r#"{"date":1}"#;
|
let json = r#"{"date":1}"#;
|
||||||
let expected = DateTime::from_naive_utc_and_offset(
|
let expected = DateTime::from_timestamp(1, 0).unwrap();
|
||||||
chrono::NaiveDateTime::from_timestamp_opt(1, 0).unwrap(),
|
|
||||||
Utc,
|
|
||||||
);
|
|
||||||
|
|
||||||
let Struct { date } = serde_json::from_str(json).unwrap();
|
let Struct { date } = serde_json::from_str(json).unwrap();
|
||||||
assert_eq!(date, Some(expected));
|
assert_eq!(date, Some(expected));
|
||||||
|
|
|
@ -36,8 +36,6 @@ pub struct Animation {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::types::FileMeta;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -36,8 +36,6 @@ pub struct Audio {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::types::{FileMeta, Seconds};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -702,7 +702,7 @@ mod tests {
|
||||||
can_invite_users: true,
|
can_invite_users: true,
|
||||||
can_pin_messages: true,
|
can_pin_messages: true,
|
||||||
until_date: UntilDate::Date(
|
until_date: UntilDate::Date(
|
||||||
chrono::NaiveDateTime::from_timestamp_opt(1620000000, 0).unwrap().and_utc(),
|
chrono::DateTime::from_timestamp(1620000000, 0).unwrap(),
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,15 +15,8 @@ use tokio::{
|
||||||
use tokio_util::codec::{Decoder, FramedRead};
|
use tokio_util::codec::{Decoder, FramedRead};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow, convert::Infallible, fmt, future::Future, io, iter, mem, path::PathBuf, pin::Pin,
|
||||||
convert::{Infallible, TryFrom},
|
sync::Arc, task,
|
||||||
fmt,
|
|
||||||
future::Future,
|
|
||||||
io, iter, mem,
|
|
||||||
path::PathBuf,
|
|
||||||
pin::Pin,
|
|
||||||
sync::Arc,
|
|
||||||
task,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::types::InputSticker;
|
use crate::types::InputSticker;
|
||||||
|
|
|
@ -1748,7 +1748,7 @@ mod tests {
|
||||||
Message {
|
Message {
|
||||||
id: MessageId(198283),
|
id: MessageId(198283),
|
||||||
thread_id: None,
|
thread_id: None,
|
||||||
date: chrono::NaiveDateTime::from_timestamp_opt(1567927221, 0).unwrap().and_utc(),
|
date: chrono::DateTime::from_timestamp(1567927221, 0).unwrap(),
|
||||||
chat: Chat {
|
chat: Chat {
|
||||||
id: ChatId(250918540),
|
id: ChatId(250918540),
|
||||||
kind: ChatKind::Private(ChatPrivate {
|
kind: ChatKind::Private(ChatPrivate {
|
||||||
|
|
|
@ -264,7 +264,6 @@ pub enum MessageEntityKind {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use cool_asserts::assert_matches;
|
use cool_asserts::assert_matches;
|
||||||
use MessageEntity;
|
|
||||||
use MessageEntityKind::*;
|
use MessageEntityKind::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -2,10 +2,7 @@
|
||||||
// (for built ins there no warnings, but for (De)Serialize, there are)
|
// (for built ins there no warnings, but for (De)Serialize, there are)
|
||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
|
|
||||||
use std::{
|
use std::str::FromStr;
|
||||||
convert::{TryFrom, TryInto},
|
|
||||||
str::FromStr,
|
|
||||||
};
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -184,8 +181,8 @@ impl FromStr for ParseMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[allow(deprecated)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(deprecated)]
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ pub enum ResponseParameters {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::types::{ChatId, Seconds};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn migrate_to_chat_id_deserialization() {
|
fn migrate_to_chat_id_deserialization() {
|
||||||
|
|
|
@ -26,8 +26,11 @@ impl Seconds {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns [`chrono::Duration`] equivalent of this duration.
|
/// Returns [`chrono::Duration`] equivalent of this duration.
|
||||||
|
// FIXME: rename to `time_delta` (the new name of `chrono::Duration`)?
|
||||||
pub fn chrono_duration(self) -> chrono::Duration {
|
pub fn chrono_duration(self) -> chrono::Duration {
|
||||||
chrono::Duration::seconds(self.seconds() as i64)
|
// Unwrap: `self.seconds()` is a `u32`, which is always between `-i64::MAX/1000`
|
||||||
|
// and `i64::MAX/1000`
|
||||||
|
chrono::Duration::try_seconds(self.seconds() as i64).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{convert::TryFrom, ops::Deref};
|
use std::ops::Deref;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
|
@ -384,16 +384,13 @@ mod test {
|
||||||
MessageId, MessageKind, Update, UpdateId, UpdateKind, User, UserId,
|
MessageId, MessageKind, Update, UpdateId, UpdateKind, User, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
use chrono::DateTime;
|
||||||
|
|
||||||
// TODO: more tests for deserialization
|
// TODO: more tests for deserialization
|
||||||
#[test]
|
#[test]
|
||||||
fn message() {
|
fn message() {
|
||||||
let timestamp = 1_569_518_342;
|
let timestamp = 1_569_518_342;
|
||||||
let date = DateTime::from_naive_utc_and_offset(
|
let date = DateTime::from_timestamp(timestamp, 0).unwrap();
|
||||||
NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(),
|
|
||||||
Utc,
|
|
||||||
);
|
|
||||||
|
|
||||||
let json = r#"{
|
let json = r#"{
|
||||||
"update_id":892252934,
|
"update_id":892252934,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::iter::FromIterator;
|
|
||||||
|
|
||||||
pub(crate) struct Unzip<A, B>(pub A, pub B);
|
pub(crate) struct Unzip<A, B>(pub A, pub B);
|
||||||
|
|
||||||
impl<A, B, T, U> FromIterator<(T, U)> for Unzip<A, B>
|
impl<A, B, T, U> FromIterator<(T, U)> for Unzip<A, B>
|
||||||
|
|
|
@ -129,9 +129,11 @@ async fn mute_user(bot: Bot, msg: Message, time: Duration) -> ResponseResult<()>
|
||||||
|
|
||||||
// Calculates time of user restriction.
|
// Calculates time of user restriction.
|
||||||
fn calc_restrict_time(time: u64, unit: UnitOfTime) -> Duration {
|
fn calc_restrict_time(time: u64, unit: UnitOfTime) -> Duration {
|
||||||
|
// FIXME: actually handle the case of too big integers correctly, instead of
|
||||||
|
// unwrapping
|
||||||
match unit {
|
match unit {
|
||||||
UnitOfTime::Hours => Duration::hours(time as i64),
|
UnitOfTime::Hours => Duration::try_hours(time as i64).unwrap(),
|
||||||
UnitOfTime::Minutes => Duration::minutes(time as i64),
|
UnitOfTime::Minutes => Duration::try_minutes(time as i64).unwrap(),
|
||||||
UnitOfTime::Seconds => Duration::seconds(time as i64),
|
UnitOfTime::Seconds => Duration::try_seconds(time as i64).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
use teloxide::{
|
use teloxide::{prelude::*, types::ParseMode, utils::html};
|
||||||
dispatching::Dispatcher,
|
|
||||||
prelude::*,
|
|
||||||
types::{ChatMemberUpdated, ParseMode, Update},
|
|
||||||
utils::html,
|
|
||||||
};
|
|
||||||
use teloxide_core::adaptors::DefaultParseMode;
|
use teloxide_core::adaptors::DefaultParseMode;
|
||||||
|
|
||||||
/// We use a type alias to be able to write just `bot: Bot` in handlers, instead
|
/// We use a type alias to be able to write just `bot: Bot` in handlers, instead
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use teloxide::{
|
use teloxide::{prelude::*, types::Dice, utils::command::BotCommands};
|
||||||
prelude::*,
|
|
||||||
types::{Dice, Update, UserId},
|
|
||||||
utils::command::BotCommands,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|
|
@ -3,7 +3,6 @@ use teloxide::{
|
||||||
types::{
|
types::{
|
||||||
InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText,
|
InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText,
|
||||||
},
|
},
|
||||||
Bot,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
use std::{
|
use std::{fmt::Debug, sync::Arc};
|
||||||
fmt::Debug,
|
|
||||||
marker::{Send, Sync},
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use teloxide_core::types::ChatId;
|
use teloxide_core::types::ChatId;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
|
||||||
future::Future,
|
future::Future,
|
||||||
mem,
|
mem,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
|
|
|
@ -115,8 +115,6 @@ pub fn user_mention_or_link(user: &User) -> String {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use teloxide_core::types::UserId;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -157,7 +157,6 @@ pub fn user_mention_or_link(user: &User) -> String {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use teloxide_core::types::{User, UserId};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bold() {
|
fn test_bold() {
|
||||||
|
|
Loading…
Reference in a new issue