Skip to content

Commit

Permalink
type infer abuse =)
Browse files Browse the repository at this point in the history
  • Loading branch information
orzklv committed Nov 16, 2023
1 parent 9127b1e commit 629ebf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions src/functions/inline.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -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<Crate> = crates_client.crates(request).await.unwrap().crates;

if request.is_empty() {
return {
Expand All @@ -64,10 +62,8 @@ pub async fn inline(
};
}

let mut result: Vec<InlineQueryResult> = Vec::new();

for c in request.iter() {
result.push(InlineQueryResult::Article(
let request: Vec<InlineQueryResult> = request.iter().map(|c: &Crate| {
InlineQueryResult::Article(
InlineQueryResultArticle::new(
uuid::Uuid::new_v4(),
c.name.clone(),
Expand All @@ -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(())
}
4 changes: 2 additions & 2 deletions src/utils/inmgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pub fn view_generate(c: &Crate) -> String {
));
result.push_str(&format!(
"⌚️ <b>Yaratilgan:</b> <code>{}</code>\n",
c.created_at.date_naive().to_string()
c.created_at.date_naive()
));
result.push_str(&format!(
"📡 <b>Yangilangan:</b> <code>{}</code>\n",
c.updated_at.date_naive().to_string()
c.updated_at.date_naive()
));
result.push_str(&format!(
"📰 <b>Ma'lumot:</b> <code>{}{}</code>\n\n",
Expand Down

0 comments on commit 629ebf6

Please sign in to comment.