How to use prost crate in Rust protobuf

Enable the protobuf feature in axum-extra and use the Protobuf extractor to handle binary message serialization.

Enable the protobuf feature in axum-extra and use the Protobuf<T> extractor or response type with structs deriving prost::Message.

[dependencies]
axum-extra = { version = "0.12.6", features = ["protobuf"] }
prost = "0.14"

[build-dependencies]
prost-build = "0.14"
use axum::{routing::post, Router};
use axum_extra::protobuf::Protobuf;
use prost::Message;

#[derive(prost::Message)]
struct CreateUser {
    #[prost(string, tag = "1")]
    email: String,
}

async fn create_user(Protobuf(payload): Protobuf<CreateUser>) -> String {
    payload.email
}

let app = Router::new().route("/users", post(create_user));