在 Rust 中我们如何查找宏?

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

例如,我正在使用

salvo_oapi
板条箱

我有以下 Rust 代码:

use bson::doc;
use salvo::prelude::*;

use crate::{
    features::auth::models::user::{get_user_from_depot, User},
    utils::api_error::ApiError,
};

/// How to know what macros this cargo supports? Docs are unclear
#[endpoint(tags("Auth"), operationId = "fetch_user")]
pub async fn fetch_user(depot: &mut Depot) -> Result<Json<User>, ApiError> {
    let user = get_user_from_depot(depot)?;

    Ok(Json(user.clone()))
}

当我打开货物或宏源代码时,我找不到任何允许的宏所在的位置以及它们的名称和输入是什么;非常令人沮丧的经历。

rust rust-cargo
1个回答
0
投票

有关

endpoint
宏的具体问题/评论确实由
salvo-oapi
的开发人员更好地解决了。最好提出一个问题:文档here应该描述了如何使用宏,或者至少链接到指南/教程。

更一般地说,宏(任何类型)的文档并不像 Rust 中的函数文档那么容易。这是因为宏在设计上可以以非标准方式处理 AST,以允许语法扩展(在合理范围内)。因此,一个属性宏可能使用语法

#[foo(a = 1, b = 2)]
,另一个可能使用
#[foo(1, 2)]
,而另一个属性宏可能只是
#[foo]
,并带有来自注释项正文的附加“输入”。

© www.soinside.com 2019 - 2024. All rights reserved.