Changed param from array slice to implInterator on routes in builder

This commit is contained in:
Martin Berg Alstad 2024-06-27 00:12:47 +02:00
parent 752d1a9d10
commit aba28d1612

View File

@ -42,8 +42,8 @@ impl AppBuilder {
Self::default() Self::default()
} }
pub fn routes(mut self, routes: &[Router]) -> Self { pub fn routes(mut self, routes: impl IntoIterator<Item = Router>) -> Self {
self.router = routes.iter().cloned().fold(self.router, Router::merge); self.router = routes.into_iter().fold(self.router, Router::merge);
self self
} }
@ -147,7 +147,7 @@ mod tests {
let handler = tokio::spawn(async { let handler = tokio::spawn(async {
AppBuilder::new() AppBuilder::new()
.socket((Ipv4Addr::LOCALHOST, 8080)) .socket((Ipv4Addr::LOCALHOST, 8080))
.routes(&[Router::new()]) .routes([Router::new()])
.fallback(|| async { "Fallback" }) .fallback(|| async { "Fallback" })
.cors(CorsLayer::new()) .cors(CorsLayer::new())
.normalize_path(true) .normalize_path(true)