#![forbid(unsafe_code)]
pub use rust_tg_bot_raw as raw;
pub use rust_tg_bot_raw::bot::Bot;
pub use rust_tg_bot_raw::error;
pub use rust_tg_bot_raw::types;
pub use rust_tg_bot_ext as ext;
pub use rust_tg_bot_ext::prelude;
#[cfg(feature = "macros")]
pub use rust_tg_bot_macros::BotCommands;
pub struct RuntimeConfig {
pub worker_threads: Option<usize>,
pub thread_stack_size: usize,
}
impl Default for RuntimeConfig {
fn default() -> Self {
Self {
worker_threads: None,
thread_stack_size: 8 * 1024 * 1024,
}
}
}
impl RuntimeConfig {
pub fn workers(mut self, n: usize) -> Self {
self.worker_threads = Some(n);
self
}
pub fn stack_size(mut self, bytes: usize) -> Self {
self.thread_stack_size = bytes;
self
}
}
#[deprecated(since = "1.0.0-beta.2", note = "Use #[tokio::main] directly instead")]
pub fn run<F: std::future::Future<Output = ()> + Send>(future: F) {
run_configured(RuntimeConfig::default(), future);
}
pub fn run_configured<F: std::future::Future<Output = ()> + Send>(
config: RuntimeConfig,
future: F,
) {
let mut builder = tokio::runtime::Builder::new_multi_thread();
builder
.thread_stack_size(config.thread_stack_size)
.enable_all();
if let Some(n) = config.worker_threads {
builder.worker_threads(n);
}
builder
.build()
.expect("failed to build tokio runtime")
.block_on(future);
}