1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#![doc = include_str!("../README.md")]
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
use proc_macro::TokenStream;
mod api;
mod attr;
mod status;
/// A derive macro helping implemente [`Api`] trait.
/// # Example
/// ```
/// use fav_core::api::Api;
///
/// #[derive(Api)]
/// #[api(endpoint("http://abc.com"), params(&["id", "pwd"]), cookies(&["c1"]), method(POST))]
/// struct LoginApi;
///
/// # fn main() {
/// let api = LoginApi;
/// assert_eq!(api.endpoint(), "http://abc.com");
/// assert_eq!(api.params(), &["id", "pwd"]);
/// assert_eq!(api.cookie_keys(), &["c1"]);
/// assert_eq!(api.method(), reqwest::Method::POST);
/// # }
/// ```
#[proc_macro_derive(Api, attributes(api))]
pub fn derive_api(input: TokenStream) -> TokenStream {
api::derive_api(input)
}
/// A derive macro helping implemente [`Attr`] trait.
/// # Example
/// ```
/// use fav_core::attr::Attr;
///
/// #[derive(Attr)]
/// struct Res {
/// id: i32,
/// title: String,
/// }
///
/// #[derive(Attr)]
/// #[attr(id(res_id), title(res_name))]
/// struct Res_ {
/// res_id: i32,
/// res_name: String,
/// }
/// ```
/// Default fields are `id` and `title`.
/// In practice, the `Res` is comming from `protobuf-codegen`,
/// making the attribute `attr` referring to the fields needed.
#[proc_macro_derive(Attr, attributes(attr))]
pub fn derive_attr(input: TokenStream) -> TokenStream {
attr::derive_attr(input)
}
/// A derive macro helping implemente [`Status`] trait.
/// # Example
/// ```
/// use fav_core::status::Status;
///
/// #[derive(Status)]
/// struct Res {
/// status: i32,
/// }
///
/// #[derive(Status)]
/// #[status(my_status)]
/// struct Res_ {
/// my_status: i32,
/// }
/// ```
/// Default field is `status`.
/// In practice, the `Res` is comming from `protobuf-codegen`,
/// making the attribute `status` referring to the fields needed.
#[proc_macro_derive(Status, attributes(status))]
pub fn derive_status(input: TokenStream) -> TokenStream {
status::derive_status(input)
}