From 629ebf653d9eb45b04a79a1baf8f916fccd1ccb5 Mon Sep 17 00:00:00 2001 From: Sokhibjon Orzikulov Date: Fri, 17 Nov 2023 03:46:46 +0500 Subject: [PATCH] type infer abuse =) --- src/functions/inline.rs | 24 ++++++++++-------------- src/utils/inmgr.rs | 4 ++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/functions/inline.rs b/src/functions/inline.rs index ad03605..433d3e9 100644 --- a/src/functions/inline.rs +++ b/src/functions/inline.rs @@ -1,8 +1,6 @@ -use crates_io_api::AsyncClient; -use crates_io_api::CratesQuery; +use crates_io_api::{AsyncClient, CratesQuery, Crate}; use std::error::Error; -use teloxide::prelude::*; -use teloxide::types::*; +use teloxide::{prelude::*, types::*}; use crate::utils::inmgr::*; @@ -32,13 +30,13 @@ pub async fn inline( }; } - let query = CratesQuery::builder() + let request: CratesQuery = CratesQuery::builder() .search(q.query.clone()) .page(1) .page_size(50) .build(); - let request = crates_client.crates(query).await.unwrap().crates; + let request: Vec = crates_client.crates(request).await.unwrap().crates; if request.is_empty() { return { @@ -64,10 +62,8 @@ pub async fn inline( }; } - let mut result: Vec = Vec::new(); - - for c in request.iter() { - result.push(InlineQueryResult::Article( + let request: Vec = request.iter().map(|c: &Crate| { + InlineQueryResult::Article( InlineQueryResultArticle::new( uuid::Uuid::new_v4(), c.name.clone(), @@ -79,10 +75,10 @@ pub async fn inline( ) .description(c.description.clone().unwrap()) .url(url::Url::parse(&format!("https://crates.io/crates/{}", c.id)).unwrap()) - .reply_markup(kb_generate(c).into()), - )); - } + .reply_markup(kb_generate(c)), + ) + }).collect(); - bot.answer_inline_query(q.id, result).send().await?; + bot.answer_inline_query(q.id, request).send().await?; Ok(()) } diff --git a/src/utils/inmgr.rs b/src/utils/inmgr.rs index 3a27afd..bc9e447 100644 --- a/src/utils/inmgr.rs +++ b/src/utils/inmgr.rs @@ -26,11 +26,11 @@ pub fn view_generate(c: &Crate) -> String { )); result.push_str(&format!( "⌚️ Yaratilgan: {}\n", - c.created_at.date_naive().to_string() + c.created_at.date_naive() )); result.push_str(&format!( "📡 Yangilangan: {}\n", - c.updated_at.date_naive().to_string() + c.updated_at.date_naive() )); result.push_str(&format!( "📰 Ma'lumot: {}{}\n\n",