Crates.io | bit_roles |
lib.rs | bit_roles |
version | 0.2.2 |
source | src |
created_at | 2024-04-13 18:17:40.893598 |
updated_at | 2024-06-08 14:04:08.059072 |
description | Granular role management based on bit flags |
homepage | https://github.com/zignis/bit-roles |
repository | https://github.com/zignis/bit-roles |
max_upload_size | |
id | 1207749 |
size | 49,250 |
This crate enables you to implement granular role and permission management based on bit flags.
Using discrete fields | Using bit roles |
---|---|
|
|
Add bit_roles
to your project:
cargo add bit_roles
You can derive the BitRole
trait for your role enum. It ensures compile-time validation for enum discriminants. Ensure
you specify a discriminant for every enum variant; it must be either zero or a power of two. Also, remember to derive
the Copy
and Clone
traits for your enum.
If you need a manager without compile-time checks, it's also exported as BitRoleUnchecked
trait. This is useful if you
want to use raw integer values for roles or have a complex role enum definition. You will need to implement
the Into<usize>
trait for your role enum, along with deriving the Copy
and Clone
traits for it.