fmt another

This commit is contained in:
p0lunin 2020-01-23 23:19:54 +02:00
parent 1aae70048e
commit 8c2b0b6c70
5 changed files with 56 additions and 37 deletions

View file

@ -146,23 +146,25 @@ pub fn polling(
stream::unfold(
(allowed_updates, bot, 0),
move |(mut allowed_updates, bot, mut offset)| async move {
let mut req = bot.get_updates().offset(offset);
req.timeout = timeout;
req.limit = limit;
req.allowed_updates = allowed_updates.take();
move |(mut allowed_updates, bot, mut offset)| {
async move {
let mut req = bot.get_updates().offset(offset);
req.timeout = timeout;
req.limit = limit;
req.allowed_updates = allowed_updates.take();
let updates = match req.send().await {
Err(err) => vec![Err(err)],
Ok(updates) => {
if let Some(upd) = updates.last() {
offset = upd.id + 1;
let updates = match req.send().await {
Err(err) => vec![Err(err)],
Ok(updates) => {
if let Some(upd) = updates.last() {
offset = upd.id + 1;
}
updates.into_iter().map(Ok).collect::<Vec<_>>()
}
updates.into_iter().map(Ok).collect::<Vec<_>>()
}
};
};
Some((stream::iter(updates), (allowed_updates, bot, offset)))
Some((stream::iter(updates), (allowed_updates, bot, offset)))
}
},
)
.flatten()

View file

@ -39,11 +39,13 @@ pub async fn download_file_stream(
.await?
.error_for_status()?;
Ok(futures::stream::unfold(res, |mut res| async {
match res.chunk().await {
Err(err) => Some((Err(err), res)),
Ok(Some(c)) => Some((Ok(c), res)),
Ok(None) => None,
Ok(futures::stream::unfold(res, |mut res| {
async {
match res.chunk().await {
Err(err) => Some((Err(err), res)),
Ok(Some(c)) => Some((Ok(c), res)),
Ok(None) => None,
}
}
}))
}

View file

@ -159,26 +159,35 @@ where
impl Chat {
pub fn is_private(&self) -> bool {
match self.kind {
ChatKind::Private {..} => true,
_ => false
ChatKind::Private { .. } => true,
_ => false,
}
}
pub fn is_group(&self) -> bool {
match self.kind {
ChatKind::NonPrivate { kind: NonPrivateChatKind::Group {..}, .. } => true,
_ => false
ChatKind::NonPrivate {
kind: NonPrivateChatKind::Group { .. },
..
} => true,
_ => false,
}
}
pub fn is_supergroup(&self) -> bool {
match self.kind {
ChatKind::NonPrivate { kind: NonPrivateChatKind::Supergroup {..}, .. } => true,
_ => false
ChatKind::NonPrivate {
kind: NonPrivateChatKind::Supergroup { .. },
..
} => true,
_ => false,
}
}
pub fn is_channel(&self) -> bool {
match self.kind {
ChatKind::NonPrivate { kind: NonPrivateChatKind::Channel {..}, .. } => true,
_ => false
ChatKind::NonPrivate {
kind: NonPrivateChatKind::Channel { .. },
..
} => true,
_ => false,
}
}
pub fn is_chat(&self) -> bool {

View file

@ -1,8 +1,8 @@
//! Utils for working with the [HTML message style][spec].
//!
//! [spec]: https://core.telegram.org/bots/api#html-style
use std::string::String;
use crate::types::User;
use std::string::String;
/// Applies the bold font style to the string.
///
@ -89,7 +89,7 @@ pub fn escape(s: &str) -> String {
pub fn user_mention_or_link(user: &User) -> String {
match user.mention() {
Some(mention) => mention,
None => link(&user.url(), &user.full_name())
None => link(&user.url(), &user.full_name()),
}
}
@ -196,7 +196,7 @@ mod tests {
first_name: "".to_string(),
last_name: None,
username: Some("abcd".to_string()),
language_code: None
language_code: None,
};
assert_eq!(user_mention_or_link(&user_with_username), "@abcd");
let user_without_username = User {
@ -205,8 +205,11 @@ mod tests {
first_name: "Name".to_string(),
last_name: None,
username: None,
language_code: None
language_code: None,
};
assert_eq!(user_mention_or_link(&user_without_username), r#"<a href="tg://user?id=123456789">Name</a>"#)
assert_eq!(
user_mention_or_link(&user_without_username),
r#"<a href="tg://user?id=123456789">Name</a>"#
)
}
}

View file

@ -1,8 +1,8 @@
//! Utils for working with the [Markdown V2 message style][spec].
//!
//! [spec]: https://core.telegram.org/bots/api#markdownv2-style
use std::string::String;
use crate::types::User;
use std::string::String;
/// Applies the bold font style to the string.
///
@ -123,7 +123,7 @@ pub fn escape_code(s: &str) -> String {
pub fn user_mention_or_link(user: &User) -> String {
match user.mention() {
Some(mention) => mention,
None => link(&user.url(), &user.full_name())
None => link(&user.url(), &user.full_name()),
}
}
@ -258,7 +258,7 @@ mod tests {
first_name: "".to_string(),
last_name: None,
username: Some("abcd".to_string()),
language_code: None
language_code: None,
};
assert_eq!(user_mention_or_link(&user_with_username), "@abcd");
let user_without_username = User {
@ -267,8 +267,11 @@ mod tests {
first_name: "Name".to_string(),
last_name: None,
username: None,
language_code: None
language_code: None,
};
assert_eq!(user_mention_or_link(&user_without_username), r#"[Name](tg://user?id=123456789)"#)
assert_eq!(
user_mention_or_link(&user_without_username),
r#"[Name](tg://user?id=123456789)"#
)
}
}