Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter-level Depot extraction #1062

Open
johnpyp opened this issue Feb 22, 2025 · 0 comments
Open

Add parameter-level Depot extraction #1062

johnpyp opened this issue Feb 22, 2025 · 0 comments

Comments

@johnpyp
Copy link

johnpyp commented Feb 22, 2025

Is your feature request related to a problem? Please describe.

In Salvo, you have to imperatively call the depot.get() / depot.obtain() method to extract state from the depot, instead of being able to put it in the parameters.

Parameter state extraction makes for handlers that are easier to unit test and are somewhat less coupled to the specific framework, and do so without resorting to true global state.

Describe the solution you'd like
Axum and similar rust HTTP frameworks have State which works similarly to Depot in Salvo, except that you can do this:

async fn posts_handler(State(state): State<AppState>) {

    // use `state`...
}

instead of salvo like:

async fn posts_handler(depot: &mut Depot) {
  let state = depot.obtain::<AppState>().unwrap();
    // use `state`...
}

It would be great if Salvo could do similar parameter-level unwrapping with obtain, so we could write something like:

async fn posts_handler(Depot(state): Depot<AppState>) {

    // use `state`...
}

Describe alternatives you've considered
N/A

Additional context
N/A

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

No branches or pull requests

1 participant