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
//! An authorization framework with compile-time enforcement.
//!
//! `Dacquiri-derive` makes using `Dacquiri` ergonomic.
//!
//! For more information on `Dacquiri`, check out its crate documentation!
use proc_macro::TokenStream;
mod subject;
mod attribute;
mod entitlement;
/**
Marks a struct as being a `Subject`.
`Subject` structs can acquire `Attributes` resulting in them gaining entitlements.
To use this derive, simply annotate a struct with the macro.
```rust
use dacquiri::prelude::Subject;
#[derive(Subject)]
struct User {
username: String
}
```
*/
#[proc_macro_derive(Subject)]
pub fn subject_macro(input: TokenStream) -> TokenStream {
subject::handle_subject(input)
}
/**
Marks a trait as being an _entitlement_.
_Entitlements_ are implemented on any _subject_ that has acquired all of the required _attributes_. Attributes
can be specified with the `entitlement` macro like so.
```rust
#[entitlement(AttributeOne, AttributeTwo)]
pub trait MyEntitlement {
fn do_thing(&self) {
println!("This subject has AttributeOne and AttributeTwo!");
}
}
```
*/
#[proc_macro_attribute]
pub fn entitlement(args: TokenStream, input: TokenStream) -> TokenStream {
entitlement::handle_entitlement(args, input)
}
/**
Marks a function as an _attribute_.
_Attributes_ define properties that we want to test on _subjects_.
For a _subject_ to hold an _attribute_ it must pass the condition defined in the function. See the
crate level documentation for more information on how to use `#[attribute]`
*/
#[proc_macro_attribute]
pub fn attribute(args: TokenStream, input: TokenStream) -> TokenStream {
attribute::handle_attribute(args, input)
}