For example: using the salvo_oapi crate, I have the following code:
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()))
}
When I open cargo or the marco source code I can't find any place where the allowed macros are and what their names and inputs would be; very frustrating experience.
The specific question/comment about the
endpointmacro is indeed better addressed by the developers ofsalvo-oapi. Best open an issue: the docs here should have described how the macro is used, or at least linked to a guide/tutorial.More generally, documentation of macros (of any kind) is not as easy as documentation of functions in Rust. This is because macros, by design, can treat the AST in non-standard ways to allow syntax extensions (within reason). So, where one attribute macro might use the syntax
#[foo(a = 1, b = 2)], another might use#[foo(1, 2)], and yet another might be simply#[foo]with additional "inputs" coming from the body of the annotated item.