doc & feature fixes

- Remove `unstable-stream` feature
- Doc fixes
This commit is contained in:
Waffle 2020-10-20 16:52:29 +03:00
parent e79f83d4a1
commit 9bf8c02c9d
14 changed files with 67 additions and 37 deletions

View file

@ -1,19 +1,32 @@
//! Bot adaptors
//! ## Bot adaptors
//!
//! Bot adaptors are very similar to [`Iterator`] adaptors —
//! they are bots (implement [`Requester`]) which wrap other bots
//! adding new functionality.
//!
//! E.g. [`AutoSend`] allows `await`ing requests directly,
//! without need to use `.send()`.
//!
//! [`Requester`]: crate::requests::Requester
#[cfg(feature = "auto_send")]
#[cfg_attr(docsrs, doc(cfg(feature = "auto_send")))]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "auto_send")))]
pub mod auto_send;
#[cfg(feature = "cache_me")]
#[cfg_attr(docsrs, doc(cfg(feature = "cache_me")))]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "cache_me")))]
pub mod cache_me;
#[cfg(feature = "throttle")]
#[cfg_attr(docsrs, doc(cfg(feature = "throttle")))]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "throttle")))]
pub mod throttle;
pub use {
auto_send::AutoSend,
cache_me::CacheMe,
throttle::Throttle,
};
#[cfg(feature = "auto_send")]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "auto_send")))]
pub use auto_send::AutoSend;
#[cfg(feature = "cache_me")]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "cache_me")))]
pub use cache_me::CacheMe;
#[cfg(feature = "throttle")]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "throttle")))]
pub use throttle::Throttle;
// FIXME: move default `parse_mode` to adaptor

View file

@ -123,7 +123,7 @@ impl Default for Limits {
/// ## Examples
///
/// ```no_run (throttle fails to spawn task without tokio runtime)
/// use teloxide_core::{bot::Limits, requests::RequesterExt, Bot};
/// use teloxide_core::{adaptors::throttle::Limits, requests::RequesterExt, Bot};
///
/// # #[allow(deprecated)]
/// let bot = Bot::new("TOKEN").throttle(Limits::default());
@ -316,6 +316,8 @@ impl<B> Throttle<B> {
/// Creates new [`Throttle`] spawning the worker with `tokio::spawn`
///
/// Note: it's recommended to use [`RequesterExt::throttle`] instead.
///
/// [`RequesterExt::throttle`]: crate::requests::RequesterExt::throttle
pub fn new_spawn(bot: B, limits: Limits) -> Self
where
// Basically, I hate this bound.

View file

@ -1,11 +1,11 @@
use tokio::io::AsyncWrite;
use bytes::Bytes;
use tokio::{io::AsyncWrite, stream::Stream};
#[cfg(feature = "unstable-stream")]
use ::{bytes::Bytes, tokio::stream::Stream};
#[cfg(feature = "unstable-stream")]
use crate::net::download_file_stream;
use crate::{bot::Bot, net::download_file, DownloadError};
use crate::{
bot::Bot,
net::{download_file, download_file_stream},
DownloadError,
};
impl Bot {
/// Download a file from Telegram into `destination`.
@ -55,7 +55,6 @@ impl Bot {
/// [`AsyncWrite`]: tokio::io::AsyncWrite
/// [`tokio::fs::File`]: tokio::fs::File
/// [`Bot::download_file`]: crate::Bot::download_file
#[cfg(feature = "unstable-stream")]
pub async fn download_file_stream(
&self,
path: &str,

View file

@ -10,6 +10,7 @@
#![cfg_attr(all(docsrs, feature = "nightly"), feature(doc_cfg, doc_spotlight))]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
#![forbid(unsafe_code)]
#![cfg_attr(feature = "full", deny(broken_intra_doc_links))]
//#![deny(missing_docs)]
#[macro_use]
@ -22,15 +23,15 @@ pub use self::{
errors::{ApiError, DownloadError, RequestError},
};
pub mod adaptors;
pub mod payloads;
pub mod prelude;
pub mod requests;
pub mod types;
pub mod adaptors;
// reexported
mod errors;
mod bot;
mod errors;
// implementation details
mod net;

View file

@ -27,12 +27,11 @@ where
Ok(())
}
#[cfg(feature = "unstable-stream")]
pub async fn download_file_stream(
client: &Client,
token: &str,
path: &str,
) -> Result<impl Stream<Item = reqwest::Result<Bytes>>, reqwest::Error> {
) -> Result<impl futures::Stream<Item = reqwest::Result<bytes::Bytes>>, reqwest::Error> {
let res = client
.get(&super::file_url(TELEGRAM_API_URL, token, path))
.send()

View file

@ -1,8 +1,5 @@
#[cfg(feature = "unstable-stream")]
pub(crate) use download::download_file_stream;
pub(crate) use self::{
download::download_file,
download::{download_file, download_file_stream},
request::{request_json, request_json2, request_multipart, request_multipart2},
telegram_response::TelegramResponse,
};

View file

@ -1,3 +1,4 @@
/// Payloads - data types sended to relegram
pub mod setters;
mod get_me;

View file

@ -1 +1,3 @@
//! Crate prelude
pub use crate::requests::Requester;

View file

@ -1,4 +1,4 @@
//! API requests.
//! Telegram API requests.
mod has_payload;
mod payload;

View file

@ -14,6 +14,8 @@ use crate::requests::{HasPayload, Output};
/// This is crucial for request wrappers which may want to cancel and/or never
/// send the underlying request. E.g.: [`Throttle<B>`]'s `send_ref` calls
/// `B::send_ref` while _not_ meaning to really send the request right now.
///
/// [`Throttle<B>`]: crate::adaptors::Throttle
#[cfg_attr(all(docsrs, feature = "nightly"), doc(spotlight))]
pub trait Request: HasPayload {
/*

View file

@ -4,7 +4,7 @@ use crate::{
types::ChatId,
};
/// The trait implemented by all bots & bot wrappers.
/// The trait implemented by all bots & bot adaptors.
/// Essentially a request builder factory (?).
///
/// _This trait is included in the crate's [`prelude`](crate::prelude)_.

View file

@ -1,10 +1,20 @@
use crate::{
adaptors::{CacheMe, throttle::Limits, Throttle, AutoSend},
requests::Requester,
};
use crate::requests::Requester;
#[cfg(feature = "cache_me")]
use crate::adaptors::CacheMe;
#[cfg(feature = "auto_send")]
use crate::adaptors::AutoSend;
#[cfg(feature = "throttle")]
use crate::adaptors::throttle::{Limits, Throttle};
pub trait RequesterExt: Requester {
/// Add `get_me` caching ability, see [`CacheMe`] for more.
///
/// [`CacheMe`]:
#[cfg(feature = "cache_me")]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "cache_me")))]
fn cache_me(self) -> CacheMe<Self>
where
Self: Sized,
@ -13,6 +23,8 @@ pub trait RequesterExt: Requester {
}
/// Send requests automatically, see [`AutoSend`] for more.
#[cfg(feature = "auto_send")]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "auto_send")))]
fn auto_send(self) -> AutoSend<Self>
where
Self: Sized,
@ -23,6 +35,8 @@ pub trait RequesterExt: Requester {
/// Add throttling ability, see [`Throttle`] for more.
///
/// Note: this spawns the worker, just as [`Throttle::new_spawn`].
#[cfg(feature = "throttle")]
#[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "throttle")))]
fn throttle(self, limits: Limits) -> Throttle<Self>
where
Self: Sized,

View file

@ -27,14 +27,14 @@ pub enum ChatMemberKind {
Kicked(Kicked),
}
/// Creator of the group. This struct is part of the [`ChatmemberKind`] enum.
/// Creator of the group. This struct is part of the [`ChatMemberKind`] enum.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Creator {
/// Custom title for this user.
pub custom_title: Option<String>,
}
/// Administrator of the group. This struct is part of the [`ChatmemberKind`]
/// Administrator of the group. This struct is part of the [`ChatMemberKind`]
/// enum.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Administrator {
@ -81,7 +81,7 @@ pub struct Administrator {
pub can_promote_members: bool,
}
/// User, restricted in the group. This struct is part of the [`ChatmemberKind`]
/// User, restricted in the group. This struct is part of the [`ChatMemberKind`]
/// enum.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Restricted {
@ -106,7 +106,7 @@ pub struct Restricted {
pub can_add_web_page_previews: bool,
}
/// User kicked from the group. This struct is part of the [`ChatmemberKind`]
/// User kicked from the group. This struct is part of the [`ChatMemberKind`]
/// enum.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Kicked {

View file

@ -1,4 +1,4 @@
//! API types.
//! Telergam API types.
pub use allowed_update::*;
pub use animation::*;