13 releases
Uses new Rust 2024
| 0.1.12 | Dec 17, 2025 |
|---|---|
| 0.1.11 | Nov 22, 2025 |
| 0.1.4 | Oct 16, 2025 |
#254 in #token
75 downloads per month
Used in 10 crates
(9 directly)
55KB
436 lines
sa-token-macro
Procedural macros for sa-token-rust.
Features
- 🎯 Annotation Style: Java-like annotation syntax
- ✅ Compile-time Checking: Catch errors before runtime
- 🔧 Easy to Use: Decorator-style authentication
- 📝 Comprehensive: All authentication scenarios covered
Installation
[dependencies]
sa-token-macro = "0.1.12"
sa-token-core = "0.1.12"
Macros
Login Check
use sa_token_macro::sa_check_login;
#[sa_check_login]
async fn protected_route() -> &'static str {
"This route requires login"
}
Permission Check
use sa_token_macro::sa_check_permission;
#[sa_check_permission("user:list")]
async fn list_users() -> &'static str {
"User list"
}
Role Check
use sa_token_macro::sa_check_role;
#[sa_check_role("admin")]
async fn admin_panel() -> &'static str {
"Admin panel"
}
Multiple Permissions (AND)
use sa_token_macro::sa_check_permissions_and;
#[sa_check_permissions_and("user:list", "user:edit")]
async fn manage_users() -> &'static str {
"Manage users"
}
Multiple Permissions (OR)
use sa_token_macro::sa_check_permissions_or;
#[sa_check_permissions_or("user:view", "user:list")]
async fn view_users() -> &'static str {
"View users"
}
Ignore Authentication
use sa_token_macro::sa_ignore;
#[sa_ignore]
async fn public_route() -> &'static str {
"Public access"
}
Permission Matching Rules
See Permission Matching Documentation for detailed rules.
Author
金书记
License
Licensed under either of Apache-2.0 or MIT.
Dependencies
~140–530KB
~13K SLoC