Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kanarus
Copy link
Member

@kanarus kanarus commented Feb 9, 2025

Before, mismatch of path params at registration like

// requires 1 path param
async fn hello(name: &str) -> String {
    format!("Hello, {name}!")
}

// capture 0 path params
Ohkami::new((
    "/hello".GET(hello),
))

causes undefined behavior, actually ( Ohkami trusted users TOO much that they never write such codes ) .

This PR:

  • adds n_params to IntoHandler and store it in HandlerSet.
  • updates base::Router's routes to hold HashMap<RouteSegments, TupleMap<Method, HandlerMeta>>, here HandlerMeta stores n_params
  • updates base::Router::finalize to check that each handler's n_params doesn't exceeds the number of param segments of corresponded RouteSegments. if exceeds, safely panic with friendly message.

The n_paramss exist only in preparing step, and the check is executed before starting serving. So this PR does NOT affect the performance.

@kanarus kanarus changed the title Check the number of required path params in IntoHandler Check the number of required path params Feb 9, 2025
@kanarus kanarus merged commit a1e9800 into v0.23 Feb 9, 2025
3 checks passed
@kanarus kanarus deleted the handler/count-path-params-number-in-IntoHandler branch February 9, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant