Skip to content

Commit d8ded8e

Browse files
Timothy FlowersTimothy Flowers
authored andcommitted
Updates the README to be more concise
1 parent 5940354 commit d8ded8e

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

README.md

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,63 @@
11
# Attribution
22

3-
_This crate is a work in progress. This README will be valid once it is complete._
3+
Attribution is a crate that makes parsing attribute-style procedural macros as
4+
easy as declaring a struct.
45

5-
Attribution is a crate containing macros that are designed to help in the
6-
development of attribute style procedural macros. Specifically it is designed to
7-
help in the parsing of attribute arguments. Attribution is able to do this
8-
without the user having to know how to parse the attribute arguments.
9-
Attribution's goal is to make parsing the attribute as easy as declaring its
10-
parameters
6+
## Example Usage
117

12-
## Attribution in Action
13-
14-
Here's a quick example how Attribution helps make implementing attribute style
15-
proc macros easier. For this example, a simple attribute called `ez_log` will be
16-
used. The purpose of the attribute is to log a message at the beginning of the
17-
function call. The actual implementation of the proc macro won't be written but
18-
the logic to parse it attribute arguments using Attribution will be shown.
19-
20-
**DISCLAIMER:** At the time of this writing `ez_log` is not an existing rust
21-
crate. If that should change in the future and you (as the owner) would like me
22-
to change this example, please feel free to open an issue.
23-
24-
Let the following be an example usage of this example macro.
8+
Let's see it in action. Imagine that we want to create a procedural macro
9+
attribute called `ez_trace`. That adds a custom message to the beginning and
10+
end of a method call. See the example below for how the usage of this attribute
11+
would appear.
2512

2613
```rust
27-
use ez_log::ez_log;
28-
29-
#[ez_log(msg = "inside my_function")]
30-
fn my_function(a: i32, b: i32) -> i32 {
31-
a + b
14+
#[ez_trace(start = "Starting...", end = "Ending...")]
15+
fn my_func() {
16+
println!("Do some work");
3217
}
3318
```
3419

35-
The attribute takes a single parameter, `msg` which is a string. To parse the
36-
argument within the proc macro write the following.
20+
In order to parse such an attribute we would need to add the following code to
21+
our hypothetical procedural macro crate.
3722

23+
**lib.rs**
3824
```rust
39-
use attribution::attribute_args;
40-
use proc_macro::TokenStream;
41-
use syn::parse_macro_input;
42-
43-
#[attribute_args]
44-
struct EzLogArgs {
45-
msg: &'static str
25+
#[attr_args]
26+
struct EzTraceArgs {
27+
start: String,
28+
end: String
4629
}
4730

48-
fn ez_log(attr: TokenStream, input: TokenStream) -> TokenStream {
49-
let args = parse_macro_input!(attr as EzLogArgs);
50-
// ...
31+
fn ez_trace(attr_ts: TokenStream, func_ts: TokenStream) -> TokenStream {
32+
let args = syn::parse_macro_input!(attr_ts as EzTraceArgs);
33+
/// Remaining macro implementation...
5134
}
5235
```
5336

54-
The `attribute_args` attribute generates the code necessary to parse an
55-
`EzLogArgs` struct from the `TokenStream` using the
56-
[parse_macro_input!](https://docs.rs/syn/0.15.39/syn/macro.parse_macro_input.html)
57-
macro from the [syn](https://crates.io/crates/syn) crate. adding new parameters
58-
to the macro is as easy as adding new fields to the `EzLogArgs` struct.
37+
With the above code, `args` will contain the string values `start` and `end`
38+
("Starting..." and "Ending..." respectively). To parse additional parameters
39+
simply add more fields to the `EzTraceArgs` struct. Currently the supported
40+
types are: `String`, `u64`, and `bool`. Support for more standard library types
41+
will arrive in the future and the ability to use custom types will also arrive
42+
later.
43+
44+
## Contributing
45+
46+
If you'd like to support further development of attribution there are a few
47+
things you can do. Feel free to open an issue [here]
48+
(https://github.com/chuck-flowers/attribution/issues/new) for any bugs you come
49+
across or any feature requests you have for future releases of attribution. For
50+
bugs, please include the minimal code required to produce the bug in the issue
51+
description along with what you expect to happen and what actually happens.
52+
53+
I will be adding a link soon to accept financial donations if you so wish. I
54+
will continue to work on the project regardless of financial donations but if
55+
you find attribution useful and would like to buy me a cup of coffee I would
56+
be very grateful.
57+
58+
I don't intend to accept pull requests at this time because I feel it would be
59+
unethical to solicit donations and accept pull requests without financially
60+
compensating the submitter. I don't want to get bogged down in the process of
61+
determining what a fair share of the donations would be. I also feel the scope
62+
and codebase of the project is small enough that I should be able to handle any
63+
issues that appear in a timely manner.

0 commit comments

Comments
 (0)