Repository: tokio-rs/axum
File: axum/src/routing/mod.rs (Rust)

Code before:
    /// or nested under.
    ///
    /// # Example
    ///
    /// ```
    /// use axum::{Router, routing::get, extract::State};
    ///
    /// #[derive(Clone)]
    /// struct AppState {}
    ///
    /// // A router that will be nested under the `app` router.
    /// //
    /// // By using `inherit_state` we'll reuse the state from the `app` router.
    /// let nested_router = Router::inherit_state()
    ///     .route("/bar", get(|state: State<AppState>| async {}));
    ///
    /// // A router that will be merged into the `app` router.
    /// let merged_router = Router::inherit_state()
    ///     .route("/baz", get(|state: State<AppState>| async {}));
    ///
    /// let app = Router::with_state(AppState {})
    ///     .route("/", get(|state: State<AppState>| async {}))
    ///     .nest("/foo", nested_router)
    ///     .merge(merged_router);
    ///
    /// `app` now has routes for `/`, `/foo/bar`, and `/baz` that all use the same state.
    /// # let _: Router<AppState> = app;
    /// ```
    pub fn inherit_state() -> Self {
        Self {
            state: None,
            routes: Default::default(),
            node: Default::default(),
            fallback: Fallback::Default(Route::new(NotFound)),
        }
    }

    #[doc = include_str!("../docs/routing/route.md")]
    #[track_caller]
    pub fn route(mut self, path: &str, method_router: MethodRouter<S, B>) -> Self {
        #[track_caller]
        fn validate_path(path: &str) {
            if path.is_empty() {
                panic!("Paths must start with a `/`. Use \"/\" for root routes");
            } else if !path.starts_with('/') {
                panic!("Paths must start with a `/`");
            }
        }

        validate_path(path);


Review comment (suggestion):
```suggestion
    /// // `app` now has routes for `/`, `/foo/bar`, and `/baz` that all use the same state.
```

Code after:
    /// or nested under.
    ///
    /// # Example
    ///
    /// ```
    /// use axum::{Router, routing::get, extract::State};
    ///
    /// #[derive(Clone)]
    /// struct AppState {}
    ///
    /// // A router that will be nested under the `app` router.
    /// //
    /// // By using `inherit_state` we'll reuse the state from the `app` router.
    /// let nested_router = Router::inherit_state()
    ///     .route("/bar", get(|state: State<AppState>| async {}));
    ///
    /// // A router that will be merged into the `app` router.
    /// let merged_router = Router::inherit_state()
    ///     .route("/baz", get(|state: State<AppState>| async {}));
    ///
    /// let app = Router::with_state(AppState {})
    ///     .route("/", get(|state: State<AppState>| async {}))
    ///     .nest("/foo", nested_router)
    ///     .merge(merged_router);
    ///
    /// // `app` now has routes for `/`, `/foo/bar`, and `/baz` that all use the same state.
    /// # let _: Router<AppState> = app;
    /// ```
    pub fn inherit_state() -> Self {
        Self {
            state: None,
            routes: Default::default(),
            node: Default::default(),
            fallback: Fallback::Default(Route::new(NotFound)),
        }
    }

    #[doc = include_str!("../docs/routing/route.md")]
    #[track_caller]
    pub fn route(mut self, path: &str, method_router: MethodRouter<S, B>) -> Self {
        #[track_caller]
        fn validate_path(path: &str) {
            if path.is_empty() {
                panic!("Paths must start with a `/`. Use \"/\" for root routes");
            } else if !path.starts_with('/') {
                panic!("Paths must start with a `/`");
            }
        }

        validate_path(path);