Skip to content

Commit 2959e38

Browse files
committed
fix example
1 parent 7428718 commit 2959e38

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

examples/error-handling-and-dependency-injection/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ publish = false
66

77
[dependencies]
88
axum = { path = "../../axum" }
9+
futures-util = "0.3"
910
serde = { version = "1.0", features = ["derive"] }
1011
serde_json = "1.0"
1112
tokio = { version = "1.0", features = ["full"] }

examples/error-handling-and-dependency-injection/src/main.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use axum::{
1414
routing::{get, post},
1515
Json, Router,
1616
};
17+
use futures_util::future::BoxFuture;
1718
use serde::{Deserialize, Serialize};
1819
use serde_json::json;
1920
use std::sync::Arc;
@@ -109,12 +110,12 @@ impl IntoResponse for AppError {
109110
struct ExampleUserRepo;
110111

111112
impl UserRepo for ExampleUserRepo {
112-
async fn find(&self, _user_id: Uuid) -> Result<User, UserRepoError> {
113-
unimplemented!()
113+
fn find(&self, _user_id: Uuid) -> BoxFuture<Result<User, UserRepoError>> {
114+
Box::pin(async { unimplemented!() })
114115
}
115116

116-
async fn create(&self, _params: CreateUser) -> Result<User, UserRepoError> {
117-
unimplemented!()
117+
fn create(&self, _params: CreateUser) -> BoxFuture<Result<User, UserRepoError>> {
118+
Box::pin(async { unimplemented!() })
118119
}
119120
}
120121

@@ -124,10 +125,10 @@ type DynUserRepo = Arc<dyn UserRepo + Send + Sync>;
124125
/// A trait that defines things a user repo might support.
125126
trait UserRepo {
126127
/// Loop up a user by their id.
127-
async fn find(&self, user_id: Uuid) -> Result<User, UserRepoError>;
128+
fn find(&self, user_id: Uuid) -> BoxFuture<Result<User, UserRepoError>>;
128129

129130
/// Create a new user.
130-
async fn create(&self, params: CreateUser) -> Result<User, UserRepoError>;
131+
fn create(&self, params: CreateUser) -> BoxFuture<Result<User, UserRepoError>>;
131132
}
132133

133134
#[derive(Debug, Serialize)]

0 commit comments

Comments
 (0)