Flatten teloxide module structure

This commit is contained in:
Maybe Waffle 2022-11-18 18:52:02 +04:00
parent a435266e89
commit aa8be1cd15
27 changed files with 35 additions and 43 deletions

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,13 @@
//! [`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;
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

@ -93,23 +93,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};
#[cfg(feature = "sqlite-storage")]
pub use crate::dispatching::dialogue::{SqliteStorage, SqliteStorageError};
use dptree::{prelude::DependencyMap, Handler};
pub use crate::storage::*;
pub use get_chat_id::GetChatId;
pub use storage::*;
use teloxide_core::types::ChatId;
use crate::{dispatching::DpHandlerDescription, types::ChatId};
use dptree::{prelude::DependencyMap, Handler};
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use super::DpHandlerDescription;
mod get_chat_id;
mod storage;
/// A handle for controlling dialogue state.
#[derive(Debug)]

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

@ -1,8 +1,6 @@
use crate::{
dispatching::{
dialogue::{GetChatId, Storage},
DpHandlerDescription,
},
dispatching::{dialogue::GetChatId, DpHandlerDescription},
storage::Storage,
types::{Me, Message},
utils::command::BotCommands,
};

View file

@ -60,16 +60,20 @@
#![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 storage;
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`].
///