轴未针对fn item<_, _, _>实施特质处理程序

问题描述 投票:0回答:1

尽管为Axum端点实现处理程序功能,但我运行以下错误

   --> qubic-rpc/src/lib.rs:90:38
    |
90  |         .route("/balances/{id}", get(routes::wallet_balance))
    |                                  --- ^^^^^^^^^^^^^^^^^^^^^^ the trait `Handler<_, _>` 
    |            is not implemented for fn item 
    |           `fn(axum::extract::Path<QubicWallet>) -> impl Future<Output = impl IntoResponse> {wallet_balance}`
    |
    |            required by a bound introduced by this call
    |

这里的定义:

wallet_balance
所有我的其他端点都可以正常工作,当我评论

pub async fn wallet_balance(Path(_wallet): Path<QubicWallet>) -> impl IntoResponse { (StatusCode::NOT_IMPLEMENTED, "Not implemented yet") }

行时,代码编译。
    

我做了一些挖掘,发现人们通常会出现此错误时有三个主要问题:
rust traits rust-axum
1个回答
0
投票

他们忘记传递到处理程序功能
  1. 他们调用该功能,而不是将其传递给
    .route("/balances/{id}", get(routes::wallet_balance))
    fn
  2. ,例如
  3. async
    我的案例:通过提取器作为参数传递的一种类型之一,在这种情况下,不实现
    route
    特征。
    我能够使用
    .route("/balances/{id}", get(routes::wallet_balance()))
  4. 宏来弄清楚这一点(很容易解释
  5. here
    ):
    添加了您的
  6. QubicWallet
板条的功能

Deserialize

添加了有问题的处理程序的宏观

debug_handler

    RE-RUN代码以找出导致性状错误的原因。就我而言:
  1. macros
    axum
    解决问题。
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.