rust_rbac/models/
subject.rs

1use async_trait::async_trait;
2use crate::error::RbacError;
3
4/// Trait to be implemented by user entities that will have roles and permissions
5#[async_trait]
6pub trait RbacSubject {
7    /// Get the unique identifier for this subject
8    fn get_id(&self) -> String;
9    
10    /// Check if the subject has a specific permission
11    async fn has_permission(&self, permission: &str) -> Result<bool, RbacError>;
12    
13    /// Check if the subject has a specific role
14    async fn has_role(&self, role: &str) -> Result<bool, RbacError>;
15    
16    /// Get all permissions for this subject (both direct and via roles)
17    async fn get_permissions(&self) -> Result<Vec<String>, RbacError>;
18    
19    /// Get all roles for this subject
20    async fn get_roles(&self) -> Result<Vec<String>, RbacError>;
21}