Why can't use both ".await?" and "rand::rng"? (-> Result<Response, Response>) #3366
-
SummaryHi, I'm trying this code: use axum::
{
http::StatusCode,
Router,
response::{IntoResponse, Response},
};
const TEST_VAR: i8 = 1;
async fn testfunc()
-> Result<bool, Response>
{
if TEST_VAR == 1
{
println!("test");
return Ok(true);
}
else
{
Err(StatusCode::INTERNAL_SERVER_ERROR.into_response())
}
}
async fn handler()
-> Result<Response, Response>
{
let rng: rand::prelude::ThreadRng = rand::rng();
testfunc().await?;
return Ok((StatusCode::OK, "test").into_response());
}
#[tokio::main]
async fn main()
{
let app = Router::new()
.fallback(handler);
let listener = tokio::net::TcpListener::bind("127.0.0.1:8080")
.await
.unwrap();
axum::serve(listener, app)
.await
.unwrap();
} But under handler for
But when i remove either this: The error goes away, could someone help me to fix it? Regards axum version0.8.4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Fixed this way:
fn create_rng()
{
let rng: rand::prelude::ThreadRng = rand::rng();
}
#[axum::debug_handler]
async fn handler()
-> Result<Response, Response>
{
create_rng();
testfunc().await?;
return Ok((StatusCode::OK, "test").into_response());
} |
Beta Was this translation helpful? Give feedback.
Fixed this way:
axum = { version = "0.8.4", features = ["macros"] }