diff --git a/axum/src/routing/path_router.rs b/axum/src/routing/path_router.rs index e9353dc7..345d6671 100644 --- a/axum/src/routing/path_router.rs +++ b/axum/src/routing/path_router.rs @@ -111,13 +111,10 @@ where } fn set_node(&mut self, path: &str, id: RouteId) -> Result<(), String> { - let mut node = - Arc::try_unwrap(Arc::clone(&self.node)).unwrap_or_else(|node| (*node).clone()); - if let Err(err) = node.insert(path, id) { - return Err(format!("Invalid route {path:?}: {err}")); - } - self.node = Arc::new(node); - Ok(()) + let node = Arc::make_mut(&mut self.node); + + node.insert(path, id) + .map_err(|err| format!("Invalid route {path:?}: {err}")) } pub(super) fn merge(