I want to use the header value from request and return in Response:
#[derive(Serialize)]
struct IndexResponse {
message: String,
}
async fn index(ctx: Context) -> ContextResult {
let hello = ctx.headers()
.get("hello")
.and_then(|v| v.to_str().ok())
.unwrap_or_else(|| "world");
ctx.build_json(IndexResponse { message: hello.to_owned() }).ok()
}
and I get the error:
❯ cargo run
Compiling messages-obsidian v0.1.0 (/Users/jkgan/Developer/Rust/messages-obsidian)
error[E0505]: cannot move out of `ctx` because it is borrowed
--> src/lib.rs:30:3
|
25 | let hello = ctx.headers()
| --- borrow of `ctx` occurs here
...
30 | ctx.build_json(IndexResponse { message: hello.to_owned() }).ok()
| ^^^ move out of `ctx` occurs here ----- borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0505`.
error: could not compile `messages-obsidian`.
To learn more, run the command again with --verbose.