Merge pull request #777 from teloxide/flatten-mods

Flatten mods
This commit is contained in:
Waffle Maybe 2022-12-15 18:08:49 +04:00 committed by GitHub
commit eb1ff32928
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 57 additions and 34 deletions

View file

@ -9,16 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Updated `axum` to v0.6.0.
- The module structure
- `teloxide::dispatching::update_listeners` => `teloxide::update_listeners`
- `teloxide::dispatching::repls` => `teloxide::repls`
- `CommandDescriptions::new` was made `const`
- The following functions were made `#[must_use]`:
- `DispatcherBuilder::{enable_ctrlc_handler, distribution_function}`
### Removed
- `rocksdb-storage` feature and associated items (See [PR #761](https://github.com/teloxide/teloxide/pull/761) for reasoning) [**BC**]
## Changed
### Deprecated
- `CommandDescriptions::new` is made `const`
- The following functions were made `#[must_use]`:
- `DispatcherBuilder::{enable_ctrlc_handler, distribution_function}`
- `teloxide::dispatching::{update_listeners, repls}` (see in the "Changed" section)
## 0.11.3 - 2022-11-28

View file

@ -20,7 +20,7 @@
use std::env;
use teloxide::{dispatching::update_listeners::webhooks, prelude::*};
use teloxide::{prelude::*, update_listeners::webhooks};
#[tokio::main]
async fn main() {

View file

@ -1,7 +1,7 @@
// The version of ngrok ping-pong-bot, which uses a webhook to receive updates
// from Telegram, instead of long polling.
use teloxide::{dispatching::update_listeners::webhooks, prelude::*};
use teloxide::{prelude::*, update_listeners::webhooks};
#[tokio::main]
async fn main() {

View file

@ -215,16 +215,30 @@
//! [`examples/dispatching_features.rs`]: https://github.com/teloxide/teloxide/blob/master/examples/dispatching_features.rs
//! [`Update`]: crate::types::Update
#[cfg(all(feature = "ctrlc_handler"))]
pub mod repls;
pub mod dialogue;
/// This module was moved to [`teloxide::update_listeners`].
///
/// [`teloxide::update_listeners`]: crate::update_listeners
#[deprecated = "This module was moved. Use `teloxide::update_listeners` instead."]
pub mod update_listeners {
pub use crate::update_listeners::*;
}
/// This module was moved to [`teloxide::repls`].
///
/// [`teloxide::repls`]: crate::repls
#[deprecated = "This module was moved. Use `teloxide::repls` instead."]
#[cfg(all(feature = "ctrlc_handler"))]
pub mod repls {
pub use crate::repls::*;
}
mod dispatcher;
mod distribution;
mod filter_ext;
mod handler_description;
mod handler_ext;
pub mod update_listeners;
pub use crate::utils::shutdown_token::{IdleShutdownError, ShutdownToken};
pub use dispatcher::{Dispatcher, DispatcherBuilder, UpdateHandler};

View file

@ -94,14 +94,15 @@
//! [`examples/dialogue.rs`]: https://github.com/teloxide/teloxide/blob/master/examples/dialogue.rs
#[cfg(feature = "redis-storage")]
pub use crate::dispatching::dialogue::{RedisStorage, RedisStorageError};
pub use self::{RedisStorage, RedisStorageError};
#[cfg(feature = "sqlite-storage")]
pub use crate::dispatching::dialogue::{SqliteStorage, SqliteStorageError};
pub use self::{SqliteStorage, SqliteStorageError};
use dptree::{prelude::DependencyMap, Handler};
pub use get_chat_id::GetChatId;
pub use storage::*;
use dptree::{prelude::DependencyMap, Handler};
use teloxide_core::types::ChatId;
use std::{fmt::Debug, marker::PhantomData, sync::Arc};

View file

@ -1,11 +1,12 @@
use crate::{
dispatching::{
distribution::default_distribution_function, update_listeners,
update_listeners::UpdateListener, DefaultKey, DpHandlerDescription, ShutdownToken,
distribution::default_distribution_function, DefaultKey, DpHandlerDescription,
ShutdownToken,
},
error_handlers::{ErrorHandler, LoggingErrorHandler},
requests::{Request, Requester},
types::{Update, UpdateKind},
update_listeners::{self, UpdateListener},
utils::shutdown_token::shutdown_check_timeout_for,
};

View file

@ -60,16 +60,19 @@
#![allow(clippy::nonstandard_macro_braces)]
#[cfg(feature = "ctrlc_handler")]
pub use dispatching::repls::{repl, repl_with_listener};
pub use repls::{repl, repl_with_listener};
#[cfg(feature = "ctrlc_handler")]
#[allow(deprecated)]
pub use dispatching::repls::{commands_repl, commands_repl_with_listener};
pub use repls::{commands_repl, commands_repl_with_listener};
pub mod dispatching;
pub mod error_handlers;
pub mod prelude;
#[cfg(all(feature = "ctrlc_handler"))]
pub mod repls;
pub mod stop;
pub mod update_listeners;
pub mod utils;
#[doc(inline)]

View file

@ -10,7 +10,7 @@ pub use crate::dispatching::{
};
#[cfg(feature = "ctrlc_handler")]
pub use crate::dispatching::repls::CommandReplExt as _;
pub use crate::repls::CommandReplExt as _;
pub use teloxide_core::{
requests::ResponseResult,

View file

@ -1,10 +1,9 @@
use crate::{
dispatching::{
update_listeners, update_listeners::UpdateListener, HandlerExt, UpdateFilterExt,
},
dispatching::{HandlerExt, UpdateFilterExt},
error_handlers::LoggingErrorHandler,
requests::{Requester, ResponseResult},
types::Update,
update_listeners::{self, UpdateListener},
utils::command::BotCommands,
};
use dptree::di::{DependencyMap, Injectable};

View file

@ -1,8 +1,9 @@
use crate::{
dispatching::{update_listeners, update_listeners::UpdateListener, UpdateFilterExt},
dispatching::UpdateFilterExt,
error_handlers::LoggingErrorHandler,
requests::{Requester, ResponseResult},
types::Update,
update_listeners::{self, UpdateListener},
};
use dptree::di::{DependencyMap, Injectable};
use std::fmt::Debug;
@ -65,7 +66,7 @@ where
#[doc = include_str!("preamble.md")]
///
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
/// [`UpdateListener`]: crate::dispatching::update_listeners::UpdateListener
/// [`UpdateListener`]: crate::update_listeners::UpdateListener
///
/// ## Signature
///

View file

@ -1,6 +1,6 @@
//! Stopping asynchronous tasks, e.g., [listeners].
//!
//! [listeners]: crate::dispatching::update_listeners
//! [listeners]: crate::update_listeners
use std::{convert::Infallible, future::Future, pin::Pin, task};

View file

@ -13,10 +13,10 @@ use std::{
use futures::{ready, stream::Stream};
use crate::{
dispatching::update_listeners::{assert_update_listener, AsUpdateStream, UpdateListener},
requests::{HasPayload, Request, Requester},
stop::{mk_stop_token, StopFlag, StopToken},
types::{AllowedUpdate, Update},
update_listeners::{assert_update_listener, AsUpdateStream, UpdateListener},
};
/// Builder for polling update listener.
@ -73,7 +73,7 @@ where
///
/// [`Dispatcher`]: crate::dispatching::Dispatcher
/// [`repl`]: fn@crate::repl
/// [`hint_allowed_updates`]: crate::dispatching::update_listeners::UpdateListener::hint_allowed_updates
/// [`hint_allowed_updates`]: crate::update_listeners::UpdateListener::hint_allowed_updates
pub fn allowed_updates(self, allowed_updates: Vec<AllowedUpdate>) -> Self {
Self { allowed_updates: Some(allowed_updates), ..self }
}

View file

@ -3,9 +3,9 @@ use std::time::Duration;
use futures::Stream;
use crate::{
dispatching::update_listeners::{AsUpdateStream, UpdateListener},
stop::StopToken,
types::{AllowedUpdate, Update},
update_listeners::{AsUpdateStream, UpdateListener},
};
/// A listener created from functions.
@ -15,7 +15,7 @@ use crate::{
///
/// For an example of usage, see [`polling`].
///
/// [`polling`]: crate::dispatching::update_listeners::polling()
/// [`polling`]: crate::update_listeners::polling()
#[non_exhaustive]
pub struct StatefulListener<St, Assf, Sf, Hauf, Thf> {
/// The state of the listener.

View file

@ -7,10 +7,10 @@ use axum::{
use tokio::sync::mpsc;
use crate::{
dispatching::update_listeners::{webhooks::Options, UpdateListener},
requests::Requester,
stop::StopFlag,
types::Update,
update_listeners::{webhooks::Options, UpdateListener},
};
/// Webhook implementation based on the [mod@axum] framework.
@ -118,7 +118,7 @@ where
R: Requester + Send,
<R as Requester>::DeleteWebhook: Send,
{
use crate::{dispatching::update_listeners::webhooks::setup_webhook, requests::Request};
use crate::{requests::Request, update_listeners::webhooks::setup_webhook};
use futures::FutureExt;
setup_webhook(&bot, &mut options).await?;
@ -156,8 +156,8 @@ pub fn axum_no_setup(
options: Options,
) -> (impl UpdateListener<Err = Infallible>, impl Future<Output = ()>, axum::Router) {
use crate::{
dispatching::update_listeners::{self, webhooks::tuple_first_mut},
stop::{mk_stop_token, StopToken},
update_listeners::{webhooks::tuple_first_mut, StatefulListener},
};
use axum::{response::IntoResponse, routing::post};
use tokio_stream::wrappers::UnboundedReceiverStream;
@ -218,7 +218,7 @@ pub fn axum_no_setup(
let stream = UnboundedReceiverStream::new(rx);
// FIXME: this should support `hint_allowed_updates()`
let listener = update_listeners::StatefulListener::new(
let listener = StatefulListener::new(
(stream, stop_token),
tuple_first_mut,
|state: &mut (_, StopToken)| state.1.clone(),
@ -276,7 +276,7 @@ impl<S> FromRequestParts<S> for XTelegramBotApiSecretToken {
'l1: 'at,
Self: 'at,
{
use crate::dispatching::update_listeners::webhooks::check_secret;
use crate::update_listeners::webhooks::check_secret;
let res = req
.headers

View file

@ -10,7 +10,7 @@ use std::{
use tokio::sync::Notify;
use crate::dispatching::update_listeners::UpdateListener;
use crate::update_listeners::UpdateListener;
/// A token which used to shutdown [`Dispatcher`].
///