Skip to content

Commit ef60f85

Browse files
committed
Add Router::reset_fallback
1 parent 9c9cbb5 commit ef60f85

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

axum/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
# Unreleased
9+
10+
- **added:** `Router::reset_fallback`
11+
812
# 0.8.3
913

1014
- **added:** Implement `From<Bytes>` for `Message` ([#3273])

axum/src/routing/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,21 @@ where
381381
})
382382
}
383383

384+
/// Reset the fallback to its default.
385+
///
386+
/// Useful to merge two routers with fallbacks, as [`merge`] doesn't allow
387+
/// both routers to have an explicit fallback. Use this method to remove the
388+
/// one you want to discard before merging.
389+
///
390+
/// [`merge`]: Self::merge
391+
pub fn reset_fallback(self) -> Self {
392+
tap_inner!(self, mut this => {
393+
this.fallback_router = PathRouter::new_fallback();
394+
this.default_fallback = true;
395+
this.catch_all_fallback = Fallback::Default(Route::new(NotFound));
396+
})
397+
}
398+
384399
fn fallback_endpoint(self, endpoint: Endpoint<S>) -> Self {
385400
tap_inner!(self, mut this => {
386401
this.fallback_router.set_fallback(endpoint);

0 commit comments

Comments
 (0)