Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for the `wasm32-unknown-unknown` target via `MaybeSend`/`MaybeSync` traits and a conditional `BoxFuture` alias ([PR #38](https://github.com/teloxide/dptree/issues/38)).
- Fallible handlers `try_filter`, `try_map`, `try_filter_map` (and their `_async` variants), which let a function return `Result` and short-circuit the whole handler chain with `ControlFlow::Break` on `Err`. Requires the handler `Output` to implement the new `Fallible` trait.
- The `Fallible` trait (with a blanket implementation for `Result<T, E>`), used by the fallible handlers to build the `Err` half of the output.
- Rename `BoxFuture` to `MaybeSendBoxFuture` to not have the same name as `futures::future::BoxFuture`.

## 0.5.1 - 2025-07-10

Expand Down
7 changes: 4 additions & 3 deletions src/di.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use futures::future::ready;

use crate::send::{BoxFuture, MaybeSend, MaybeSync};
use crate::send::{MaybeSend, MaybeSendBoxFuture, MaybeSync};

use std::{
any::{Any, TypeId},
Expand Down Expand Up @@ -204,9 +204,10 @@ where

/// A function with all dependencies satisfied.
#[cfg(not(target_arch = "wasm32"))]
pub type CompiledFn<'a, Output> = Arc<dyn Fn() -> BoxFuture<'a, Output> + Send + Sync + 'a>;
pub type CompiledFn<'a, Output> =
Arc<dyn Fn() -> MaybeSendBoxFuture<'a, Output> + Send + Sync + 'a>;
#[cfg(target_arch = "wasm32")]
pub type CompiledFn<'a, Output> = Arc<dyn Fn() -> BoxFuture<'a, Output> + 'a>;
pub type CompiledFn<'a, Output> = Arc<dyn Fn() -> MaybeSendBoxFuture<'a, Output> + 'a>;

/// Turns a synchronous function into a type that implements [`Injectable`].
pub struct Asyncify<F>(pub F);
Expand Down
4 changes: 2 additions & 2 deletions src/handler/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const FIXED_LOCATION: &Location = Location::caller();
use crate::{
description,
prelude::DependencyMap,
send::{BoxFuture, MaybeSend, MaybeSync},
send::{MaybeSend, MaybeSendBoxFuture, MaybeSync},
HandlerDescription,
};

Expand Down Expand Up @@ -139,7 +139,7 @@ type ContInner<'a, Output> =
type ContInner<'a, Output> = Box<dyn FnOnce(DependencyMap) -> HandlerResult<'a, Output> + 'a>;

/// An output type produced by a handler.
pub type HandlerResult<'a, Output> = BoxFuture<'a, ControlFlow<Output, DependencyMap>>;
pub type HandlerResult<'a, Output> = MaybeSendBoxFuture<'a, ControlFlow<Output, DependencyMap>>;

// `#[derive(Clone)]` obligates all type parameters to satisfy `Clone` as well,
// but we do not need it here because of `Arc`.
Expand Down
7 changes: 2 additions & 5 deletions src/send.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Conditional `Send`/`Sync` helpers for wasm32 target.

use std::future::Future;
use std::pin::Pin;

/// `Send` on native targets; no bound on `wasm32`.
#[cfg(not(target_arch = "wasm32"))]
pub trait MaybeSend: Send {}
Expand Down Expand Up @@ -30,6 +27,6 @@ impl<T: ?Sized> MaybeSync for T {}
/// A boxed future that is `Send` on native targets and not required to be `Send`
/// on `wasm32`.
#[cfg(not(target_arch = "wasm32"))]
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub type MaybeSendBoxFuture<'a, T> = futures::future::BoxFuture<'a, T>;
#[cfg(target_arch = "wasm32")]
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
pub type MaybeSendBoxFuture<'a, T> = futures::future::LocalBoxFuture<'a, T>;
Loading