Skip to content

Commit

Permalink
feat(router): Add missing unimplemented fallback to RoutesBuilder (#1864
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tottoto authored Aug 9, 2024
1 parent 3379d9a commit 7f46d3a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tonic/src/service/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
use tower::{Service, ServiceExt};

/// A [`Service`] router.
#[derive(Debug, Default, Clone)]
#[derive(Debug, Clone)]
pub struct Routes {
router: axum::Router,
}
Expand Down Expand Up @@ -47,6 +47,15 @@ impl RoutesBuilder {
self.routes.unwrap_or_default()
}
}

impl Default for Routes {
fn default() -> Self {
Self {
router: axum::Router::new().fallback(unimplemented),
}
}
}

impl Routes {
/// Create a new routes with `svc` already added to it.
pub fn new<S>(svc: S) -> Self
Expand All @@ -59,8 +68,7 @@ impl Routes {
S::Future: Send + 'static,
S::Error: Into<crate::Error> + Send,
{
let router = axum::Router::new().fallback(unimplemented);
Self { router }.add_service(svc)
Self::default().add_service(svc)
}

/// Create a new empty builder.
Expand Down

0 comments on commit 7f46d3a

Please sign in to comment.