我认为应该为返回 a 的函数Handler实现:asyncStatusCode
use axum::{
headers,
http::StatusCode,
routing::{delete, get, post, put},
Router,
};
pub fn create_routes() -> Router {
Router::new().route("/webhook", post(webhook_handler()))
}
#[debug_handler]
async fn webhook_handler() -> StatusCode {
StatusCode::OK
}
Run Code Online (Sandbox Code Playgroud)
use axum::{
headers,
http::StatusCode,
routing::{delete, get, post, put},
Router,
};
pub fn create_routes() -> Router {
Router::new().route("/webhook", post(webhook_handler()))
}
#[debug_handler]
async fn webhook_handler() -> StatusCode {
StatusCode::OK
}
Run Code Online (Sandbox Code Playgroud)
这看起来与文档中提供的示例几乎相同:
// `StatusCode` gives an empty response with that status code
async fn status() -> StatusCode …Run Code Online (Sandbox Code Playgroud) 我有一个包含两个字段state和children的结构体。Children 是一个包含孩子向量的选项。我正在使用 if let 语法将此选项解构回向量。
fn main() {
let mut root = Node::new2d(3);
loop {
root.calc_scores(100);
if let Some(mut children) = root.children {
let child = children.pop();
root = Node {
state: child.0,
children: None,
}
}
root.make_children();
}
}
struct Node<T> {
state: T,
children: Option<Vec<(T, i32)>>,
}
Run Code Online (Sandbox Code Playgroud)
上面的代码不能编译。它抱怨 child 是 类型Option<(Board2d,i32)>。为什么 child 仍然包含在选项枚举中?不会if let Some(mut children) = root.children{}从 Option 枚举中取出向量吗?