av/lib.rs
1use proc_macro::TokenStream;
2
3pub(crate) mod helper;
4pub(crate) mod versions;
5pub(crate) mod loglist;
6pub(crate) mod deprecation;
7
8/// The main attribute macro to annotate functions, structs, etc. with versioning information.
9/// It is able to record multiple version entries, each separated by a semicolon.
10/// Where if the last version is marked as deprecated, it will generate a #[deprecated] attribute to warn users.
11///
12/// # Example
13///
14/// The minimal example (Which will warn user):
15///
16/// ```ignore
17/// #[ver(deprecated, since = "0.1.0")]
18/// pub fn minimal_example() {
19/// println!("This is a minimal example");
20/// }
21/// ```
22///
23/// The full example with multiple versions:
24///
25/// (This will not warn user as the latest version is not deprecated. Documentation will be generated for all versions as a log. Only the latest version is shown as highlighted.)
26///
27/// ```ignore
28/// #[ver(
29/// update, since = "1.2.0", note = "Added new parameter", date = "2024-03-01", author = "Akari";
30/// stable, since = "1.1.0", note = "First stable release", date = "2024-02-01", author = "Akari";
31/// unstable, since = "0.1.0", note = "Initial implementation", date = "2024-01-01", author = "Akari"
32/// )]
33/// pub fn full_example(value: i32, new_param: bool) {
34/// println!("Value: {}, New Param: {}", value, new_param);
35/// }
36/// ```
37#[proc_macro_attribute]
38pub fn ver(attr: TokenStream, item: TokenStream) -> TokenStream {
39 let verlogs = match loglist::from_tokens(attr) {
40 Ok(v) => v,
41 Err(e) => return e,
42 };
43
44 let mut output = TokenStream::new();
45
46 // Prepend doc attributes and #[deprecated] (for most recent version only)
47 output.extend(loglist::into_doc_attrs(&verlogs));
48
49 // Append the original item
50 output.extend(item);
51
52 output
53}