This commit is contained in:
p0lunin 2020-01-10 12:26:48 +02:00
parent cadd781abf
commit 80a9ebebd2
3 changed files with 18 additions and 12 deletions

View file

@ -31,10 +31,11 @@ type FiltersWithHandlers<'a, T, E> = Vec<FilterWithHandler<'a, T, E>>;
/// use std::convert::Infallible; /// use std::convert::Infallible;
/// use teloxide::{dispatching::FilterDispatcher, RequestError}; /// use teloxide::{dispatching::FilterDispatcher, RequestError};
/// ///
/// let _ = /// let _ = FilterDispatcher::new(|err: Either<RequestError, Infallible>| {
/// FilterDispatcher::new(|err: Either<RequestError, Infallible>| async { /// async {
/// dbg!(err); /// dbg!(err);
/// }); /// }
/// });
/// ``` /// ```
/// ///
/// Or you can do it even simpler by providing the built-in error handler /// Or you can do it even simpler by providing the built-in error handler
@ -83,9 +84,11 @@ type FiltersWithHandlers<'a, T, E> = Vec<FilterWithHandler<'a, T, E>>;
/// // error handler that just ignores all errors (that can't ever happen). /// // error handler that just ignores all errors (that can't ever happen).
/// let mut dp = FilterDispatcher::<Infallible, _>::new(|_| async {}) /// let mut dp = FilterDispatcher::<Infallible, _>::new(|_| async {})
/// // Add a handler, which handles all messages sent to the bot. /// // Add a handler, which handles all messages sent to the bot.
/// .message_handler(true, |mes: Message| async move { /// .message_handler(true, |mes: Message| {
/// println!("New message: {:?}", mes); /// async move {
/// Ok(()) /// println!("New message: {:?}", mes);
/// Ok(())
/// }
/// }) /// })
/// // Add a handler, which handles all messages edited in a chat /// // Add a handler, which handles all messages edited in a chat
/// // with the bot. /// // with the bot.

View file

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

View file

@ -121,7 +121,8 @@ mod tests {
fn test_link() { fn test_link() {
assert_eq!( assert_eq!(
link("https://www.google.com/?q=foo&l=ru", "<google>"), link("https://www.google.com/?q=foo&l=ru", "<google>"),
"<a href=\"https://www.google.com/?q=foo&amp;l=ru\">&lt;google&gt;</a>", "<a href=\"https://www.google.com/?q=foo&amp;l=ru\">&lt;google&gt;\
</a>",
); );
} }