Enabled clippy warnings and fixed them

This commit is contained in:
2023-11-16 21:51:46 +03:00
parent f0116b3207
commit 6ae745fcd4
21 changed files with 129 additions and 163 deletions

View File

@ -9,17 +9,18 @@ pub async fn generic<F>(
db: DatabaseConnection,
dialogue: MainDialogue,
check: F,
no_text_message: impl Into<String>,
next: PackagedHandler<String>,
no_text_message: impl Into<String> + Send,
handler: PackagedHandler<String>,
) -> crate::Result<()>
where
for<'a> F: FnOnce(
&'a Message,
&'a DatabaseConnection,
&'a str,
) -> BoxFuture<'a, crate::Result<Option<String>>>,
&'a Message,
&'a DatabaseConnection,
&'a str,
) -> BoxFuture<'a, crate::Result<Option<String>>>
+ Send,
{
let mut handler = next.lock().await;
let mut handler = handler.lock().await;
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());

View File

@ -10,19 +10,19 @@ fn process_validity(validity: PasswordValidity) -> Result<(), String> {
let mut error_text = "Your master password is invalid:\n".to_owned();
if validity.contains(PasswordValidity::NO_LOWERCASE) {
error_text.push_str("\n* It doesn't have any lowercase characters")
error_text.push_str("\n* It doesn't have any lowercase characters");
}
if validity.contains(PasswordValidity::NO_UPPERCASE) {
error_text.push_str("\n* It doesn't have any uppercase characters")
error_text.push_str("\n* It doesn't have any uppercase characters");
}
if validity.contains(PasswordValidity::NO_NUMBER) {
error_text.push_str("\n* It doesn't have any numbers")
error_text.push_str("\n* It doesn't have any numbers");
}
if validity.contains(PasswordValidity::NO_SPECIAL_CHARACTER) {
error_text.push_str("\n* It doesn't have any special characters")
error_text.push_str("\n* It doesn't have any special characters");
}
if validity.contains(PasswordValidity::TOO_SHORT) {
error_text.push_str("\n* It is shorter than 8 characters")
error_text.push_str("\n* It is shorter than 8 characters");
}
error_text.push_str("\n\nModify your password and send it again");

View File

@ -10,9 +10,8 @@ use trim_in_place::TrimInPlace;
#[inline]
fn validate_document(document: Option<&Document>) -> Result<&Document, &'static str> {
let document = match document {
Some(document) => document,
None => return Err("You didn't send a file. Try again"),
let Some(document) = document else {
return Err("You didn't send a file. Try again");
};
if document.file.size > 1024 * 1024 * 200 {
@ -70,7 +69,7 @@ fn process_accounts(
duplicates.push(account.name.as_str());
}
if exists {
existing.push(account.name.as_str())
existing.push(account.name.as_str());
}
// If it already exists or if it is a duplicate there's no need to check the account's validity
if !duplicate && !exists && !account.validate() {
@ -91,7 +90,7 @@ fn process_accounts(
error_text,
"\n\nDuplicate names:\n{:?}",
duplicates.into_iter().format("\n")
)?
)?;
}
if !existing.is_empty() {
@ -99,7 +98,7 @@ fn process_accounts(
error_text,
"\n\nAccounts with these names already exist in the database:\n{:?}",
existing.into_iter().format("\n")
)?
)?;
}
if !invalid.is_empty() {
@ -107,7 +106,7 @@ fn process_accounts(
error_text,
"\n\nInvalid account fields:\n{:?}",
invalid.into_iter().format("\n")
)?
)?;
}
error_text.push_str("\n\nFix these problems and send the file again");
@ -128,23 +127,23 @@ fn user_from_vec(
}
}
/// Function to handle GetUser state. It doesn't actually validate anything
/// Function to handle `GetUser` state. It doesn't actually validate anything
pub async fn get_user(
bot: Throttle<Bot>,
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
next: PackagedHandler<User>,
handler: PackagedHandler<User>,
) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let mut handler = next.lock().await;
let mut handler = handler.lock().await;
if handler.func.is_none() {
let _ = dialogue.exit().await;
return Err(HandlerUsed.into());
}
if let Some("/cancel") = msg.text().map(str::trim) {
if msg.text().map(str::trim) == Some("/cancel") {
dialogue.exit().await?;
handler
.previous

View File

@ -26,9 +26,9 @@ impl MessageIds {
pub async fn alter_message(
&mut self,
bot: &Throttle<Bot>,
text: impl Into<String>,
markup: impl Into<Option<InlineKeyboardMarkup>>,
parse_mode: impl Into<Option<ParseMode>>,
text: impl Into<String> + Send,
markup: impl Into<Option<InlineKeyboardMarkup>> + Send,
parse_mode: impl Into<Option<ParseMode>> + Send,
) -> crate::Result<()> {
let mut edit = bot.edit_message_text(self.0, self.1, text);
edit.parse_mode = parse_mode.into();
@ -76,10 +76,10 @@ pub struct Handler<T: ?Sized> {
pub previous: MessageIds,
}
pub type PackagedHandler<T> = Arc<Mutex<Handler<T>>>;
pub type Packaged<T> = Arc<Mutex<Handler<T>>>;
impl<T> Handler<T> {
/// Convinience method to convert a simple async function and a previous message into PackagedHandler
/// Convinience method to convert a simple async function and a previous message into `PackagedHandler`
#[inline]
pub fn new<H>(f: H, previous: impl Into<MessageIds>) -> PackagedHandler<T>
where