Skip to content
Discussion options

You must be logged in to vote

With Go, The classic way is define an Interface, implement it and register the handler to framework. In this way, It's easy to mock it and test the correctness. Well what I want is test my Axum application just like Go application.

Rust and Go have entirely different type systems so in general you can't just "copy" the Go approach and apply it to Rust.

It looks to me like you're looking for a way to do dependency injection which there is an example for here.

To actually get your code to compile you have to:

  • Make fn helper an async function. All axum handlers must be async. So async fn helper
  • From looking at impl FromRequest for Extension<T> in the docs you can see it requires T to impl…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@LebranceBW
Comment options

@sjbodzo
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #357 on October 02, 2021 10:38.