mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Doc fixes
This commit is contained in:
parent
69adf7ef10
commit
0dc459ffcc
9 changed files with 27 additions and 42 deletions
|
@ -3,12 +3,9 @@
|
|||
//! Bot adaptors are very similar to the [`Iterator`] adaptors: they are bots
|
||||
//! wrapping other bots to alter existing or add new functionality.
|
||||
//!
|
||||
//! E.g. [`AutoSend`] allows `await`ing requests directly, no need to use
|
||||
//! `.send()`.
|
||||
//!
|
||||
//! [`Requester`]: crate::requests::Requester
|
||||
|
||||
/// [`AutoSend`] bot adaptor which allows sending a request without calling
|
||||
/// [`AutoSend`] bot adaptor which used to allow sending a request without calling
|
||||
/// [`send`].
|
||||
///
|
||||
/// [`AutoSend`]: auto_send::AutoSend
|
||||
|
|
|
@ -7,32 +7,16 @@ use crate::{
|
|||
types::*,
|
||||
};
|
||||
|
||||
/// Send requests automatically.
|
||||
/// Previously was used to send requests automatically.
|
||||
///
|
||||
/// Requests returned by `<AutoSend<_> as `[`Requester`]`>` are [`Future`]s
|
||||
/// which means that you can simply `.await` them instead of using
|
||||
/// `.send().await`.
|
||||
///
|
||||
/// Notes:
|
||||
/// 1. This wrapper should be the most outer i.e.: `AutoSend<CacheMe<Bot>>`
|
||||
/// will automatically send requests, while `CacheMe<AutoSend<Bot>>` - won't.
|
||||
/// 2. After first call to `poll` on a request you will be unable to access
|
||||
/// payload nor could you use [`send_ref`](Request::send_ref).
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use teloxide_core::{
|
||||
/// requests::{Requester, RequesterExt},
|
||||
/// types::Me,
|
||||
/// Bot,
|
||||
/// };
|
||||
///
|
||||
/// # async {
|
||||
/// let bot = Bot::new("TOKEN").auto_send();
|
||||
/// let myself: Me = bot.get_me().await?; // No .send()!
|
||||
/// # Ok::<_, teloxide_core::RequestError>(()) };
|
||||
/// ```
|
||||
/// Before addition of [`IntoFuture`] you could only `.await` [`Future`]s.
|
||||
/// This adaptor turned requests into futures, allowing to `.await` them,
|
||||
/// without calling `.send()`.
|
||||
///
|
||||
/// Now, however, all requests are required to implement `IntoFuture`, allowing
|
||||
/// you to `.await` them directly. This adaptor is noop, and shouldn't be used.
|
||||
///
|
||||
/// [`Future`]: std::future::Future
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AutoSend<B> {
|
||||
bot: B,
|
||||
|
|
|
@ -178,7 +178,7 @@ where
|
|||
|
||||
let res = match &mut request {
|
||||
ShareableRequest::Shared(shared) => shared.send_ref().await,
|
||||
ShareableRequest::Owned(owned) => owned.take().unwrap().send().await,
|
||||
ShareableRequest::Owned(owned) => owned.take().unwrap().await,
|
||||
};
|
||||
|
||||
return res;
|
||||
|
@ -197,7 +197,7 @@ where
|
|||
request.send_ref().await
|
||||
}
|
||||
(false, ShareableRequest::Shared(shared)) => shared.send_ref().await,
|
||||
(false, ShareableRequest::Owned(owned)) => owned.take().unwrap().send().await,
|
||||
(false, ShareableRequest::Owned(owned)) => owned.take().unwrap().await,
|
||||
};
|
||||
|
||||
let retry_after = res.as_ref().err().and_then(<_>::retry_after);
|
||||
|
|
|
@ -9,7 +9,7 @@ use vecrem::VecExt;
|
|||
use crate::{
|
||||
adaptors::throttle::{request_lock::RequestLock, ChatIdHash, Limits, Settings},
|
||||
errors::AsResponseParameters,
|
||||
requests::{Request, Requester},
|
||||
requests::Requester,
|
||||
};
|
||||
|
||||
const MINUTE: Duration = Duration::from_secs(60);
|
||||
|
@ -321,7 +321,7 @@ async fn freeze(
|
|||
// TODO: maybe not call `get_chat` every time?
|
||||
|
||||
// At this point there isn't much we can do with the error besides ignoring
|
||||
if let Ok(chat) = bot.get_chat(id).send().await {
|
||||
if let Ok(chat) = bot.get_chat(id).await {
|
||||
match chat.slow_mode_delay() {
|
||||
Some(delay) => {
|
||||
let now = Instant::now();
|
||||
|
|
|
@ -29,7 +29,7 @@ const TELOXIDE_TOKEN: &str = "TELOXIDE_TOKEN";
|
|||
/// use teloxide_core::prelude::*;
|
||||
///
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
/// dbg!(bot.get_me().send().await?);
|
||||
/// dbg!(bot.get_me().await?);
|
||||
/// # Ok::<_, teloxide_core::RequestError>(()) };
|
||||
/// ```
|
||||
///
|
||||
|
@ -158,7 +158,7 @@ impl Bot {
|
|||
/// let url = reqwest::Url::parse("https://localhost/tbas").unwrap();
|
||||
/// let bot = Bot::new("TOKEN").set_api_url(url);
|
||||
/// // From now all methods will use "https://localhost/tbas" as an API URL.
|
||||
/// bot.get_me().send().await
|
||||
/// bot.get_me().await
|
||||
/// # };
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
//! _Compiler support: requires rustc 1.58+_.
|
||||
//!
|
||||
//! ```
|
||||
//! # #[cfg(feature = "auto_send")]
|
||||
//! # async {
|
||||
//! # let chat_id = teloxide_core::types::ChatId(-1);
|
||||
//! use teloxide_core::{
|
||||
|
@ -20,7 +19,6 @@
|
|||
//!
|
||||
//! let bot = Bot::from_env()
|
||||
//! .parse_mode(ParseMode::MarkdownV2)
|
||||
//! .auto_send();
|
||||
//!
|
||||
//! let me = bot.get_me().await?;
|
||||
//!
|
||||
|
@ -46,7 +44,6 @@
|
|||
//! - `native-tls` = use [`native-tls`] tls implementation (**enabled by
|
||||
//! default**)
|
||||
//! - `rustls` — use [`rustls`] tls implementation
|
||||
//! - `auto_send` — enables [`AutoSend`] bot adaptor
|
||||
//! - `trace_adaptor` — enables [`Trace`] bot adaptor
|
||||
//! - `erased` — enables [`ErasedRequester`] bot adaptor
|
||||
//! - `throttle` — enables [`Throttle`] bot adaptor
|
||||
|
@ -55,6 +52,7 @@
|
|||
//! - `nightly` — enables nightly-only features, currently:
|
||||
//! - Removes some future boxing using `#![feature(type_alias_impl_trait)]`
|
||||
//! - Used to built docs (`#![feature(doc_cfg, doc_notable_trait)]`)
|
||||
//! - `auto_send` — enables [`AutoSend`] bot adaptor (deprecated)
|
||||
//!
|
||||
//! [`AutoSend`]: adaptors::AutoSend
|
||||
//! [`Trace`]: adaptors::Trace
|
||||
|
|
|
@ -42,7 +42,7 @@ pub trait Download<'w>
|
|||
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let bot = Bot::new("TOKEN");
|
||||
///
|
||||
/// let TgFile { file_path, .. } = bot.get_file("*file_id*").send().await?;
|
||||
/// let TgFile { file_path, .. } = bot.get_file("*file_id*").await?;
|
||||
/// let mut file = File::create("/tmp/test.png").await?;
|
||||
/// bot.download_file(&file_path, &mut file).await?;
|
||||
/// # Ok(()) }
|
||||
|
|
|
@ -41,6 +41,7 @@ where
|
|||
/// Send this request.
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```
|
||||
/// # async {
|
||||
/// use teloxide_core::{
|
||||
|
@ -56,6 +57,11 @@ where
|
|||
/// let method = GetMe::new();
|
||||
/// let request = JsonRequest::new(bot, method);
|
||||
/// let _: Me = request.send().await.unwrap();
|
||||
///
|
||||
/// // You can also just await requests, without calling `send`:
|
||||
/// let method = GetMe::new();
|
||||
/// let request = JsonRequest::new(bot, method);
|
||||
/// let _: Me = request.await.unwrap();
|
||||
/// # };
|
||||
/// ```
|
||||
#[must_use = "Futures are lazy and do nothing unless polled or awaited"]
|
||||
|
@ -72,6 +78,7 @@ where
|
|||
/// and then serializing it, this method should just serialize the data.)
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```
|
||||
/// # async {
|
||||
/// use teloxide_core::{prelude::*, requests::Request, types::ChatId, Bot};
|
||||
|
|
|
@ -32,8 +32,7 @@ use crate::{
|
|||
/// bot.send_message(chat_id, "<b>Text</b>")
|
||||
/// // Optional parameters can be supplied by calling setters
|
||||
/// .parse_mode(ParseMode::Html)
|
||||
/// // To send request to telegram you need to call `.send()` and await the resulting future
|
||||
/// .send()
|
||||
/// // To send request to telegram you need to `.await` the request
|
||||
/// .await?;
|
||||
/// # Ok::<_, teloxide_core::RequestError>(())
|
||||
/// # };
|
||||
|
@ -51,7 +50,7 @@ use crate::{
|
|||
/// where
|
||||
/// R: Requester,
|
||||
/// {
|
||||
/// bot.send_message(chat, "hi").send().await.expect("error")
|
||||
/// bot.send_message(chat, "hi").await.expect("error")
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg_attr(all(any(docsrs, dep_docsrs), feature = "nightly"), doc(notable_trait))]
|
||||
|
|
Loading…
Add table
Reference in a new issue