pub struct PolicyRuleBuilder { /* private fields */ }Expand description
Builder for creating PolicyRule instances with a fluent API
§Examples
use core_policy::builder::PolicyRuleBuilder;
use core_policy::{Action, Resource};
// Basic RBAC rule
let rule = PolicyRuleBuilder::new()
.for_peer("12D3KooWXYZ...")
.allow(Action::Read)
.on(Resource::File("/docs/*".into()))
.build()
.unwrap();
// ABAC rule with expiration
let rule = PolicyRuleBuilder::new()
.for_peer("technician")
.allow(Action::Read)
.on(Resource::File("/logs/*".into()))
.expires_at(1762348800)
.build()
.unwrap();
// ABAC rule with attributes
let rule = PolicyRuleBuilder::new()
.for_peer("alice")
.allow(Action::Write)
.on(Resource::File("/shared/*".into()))
.with_attribute("location", "office")
.with_attribute("security_level", "high")
.build()
.unwrap();
// ABAC rule with context expression (advanced)
let rule = PolicyRuleBuilder::new()
.for_peer("alice")
.allow(Action::Read)
.on(Resource::File("/sensitive/*".into()))
.with_context_expr("role == \"admin\" AND department == \"IT\"")? // Returns Result
.build()
.unwrap();Implementations§
Source§impl PolicyRuleBuilder
impl PolicyRuleBuilder
Sourcepub fn for_peer(self, peer_id: impl Into<String>) -> Self
pub fn for_peer(self, peer_id: impl Into<String>) -> Self
Set the peer ID that this rule applies to
Sourcepub const fn expires_at(self, timestamp: u64) -> Self
pub const fn expires_at(self, timestamp: u64) -> Self
Set the expiration timestamp (Unix seconds) - ABAC
Sourcepub fn with_attribute(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_attribute( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add an attribute for contextual access control - ABAC (legacy)
Sourcepub fn with_context_expr(self, expr: impl AsRef<str>) -> Result<Self>
pub fn with_context_expr(self, expr: impl AsRef<str>) -> Result<Self>
Add a context expression for advanced ABAC (boolean logic)
§Arguments
expr- Expression string to parse (e.g., “role == "admin" AND department == "IT"”)
§Errors
Returns PolicyError::InvalidExpression if the expression syntax is invalid
§Example
use core_policy::builder::PolicyRuleBuilder;
use core_policy::{Action, Resource};
let rule = PolicyRuleBuilder::new()
.for_peer("alice")
.allow(Action::Read)
.on(Resource::All)
.with_context_expr("role == \"admin\" AND active == \"true\"")? // Returns Result
.build()
.unwrap();Sourcepub fn build(self) -> Result<PolicyRule>
pub fn build(self) -> Result<PolicyRule>
Build the PolicyRule, returning an error if required fields are missing
§Errors
Returns PolicyError::InvalidRule if any required field is missing:
peer_idactionresource
Trait Implementations§
Source§impl Debug for PolicyRuleBuilder
impl Debug for PolicyRuleBuilder
Source§impl Default for PolicyRuleBuilder
impl Default for PolicyRuleBuilder
Source§fn default() -> PolicyRuleBuilder
fn default() -> PolicyRuleBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PolicyRuleBuilder
impl RefUnwindSafe for PolicyRuleBuilder
impl Send for PolicyRuleBuilder
impl Sync for PolicyRuleBuilder
impl Unpin for PolicyRuleBuilder
impl UnwindSafe for PolicyRuleBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more