Skip to main content

DomainPolicy

Trait DomainPolicy 

Source
pub trait DomainPolicy<E: Send + Sync + 'static>: Send + Sync {
    // Provided methods
    fn can_create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _entity: &'life1 E,
    ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn can_update<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _current: &'life1 E,
        _updated: &'life2 E,
    ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn can_delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _entity: &'life1 E,
    ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn can_restore<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _entity: &'life1 E,
    ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn enforce_create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        entity: &'life1 E,
    ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn enforce_delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        entity: &'life1 E,
    ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Core domain policy trait — governs whether CRUD operations are valid for a given entity E based on entity state alone (no auth context).

All methods default to Ok(true) (permit). Override only the methods relevant to the entity’s domain invariants.

Provided Methods§

Source

fn can_create<'life0, 'life1, 'async_trait>( &'life0 self, _entity: &'life1 E, ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Can a new entity in the given state be persisted?

Source

fn can_update<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _current: &'life1 E, _updated: &'life2 E, ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Can the entity transition from current to updated state?

Source

fn can_delete<'life0, 'life1, 'async_trait>( &'life0 self, _entity: &'life1 E, ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Can the entity be soft-deleted?

Source

fn can_restore<'life0, 'life1, 'async_trait>( &'life0 self, _entity: &'life1 E, ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Can a soft-deleted entity be restored?

Source

fn enforce_create<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 E, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Convenience: enforce can_create and map to Ok(()) or Err(reason).

Source

fn enforce_delete<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 E, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Convenience: enforce can_delete and map to Ok(()) or Err(reason).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<E: Send + Sync + 'static> DomainPolicy<E> for AllOfPolicy<E>

Source§

impl<E: Send + Sync + 'static> DomainPolicy<E> for AnyOfPolicy<E>

Source§

impl<E: Send + Sync + 'static> DomainPolicy<E> for DenyAllPolicy<E>

Source§

impl<E: Send + Sync + 'static> DomainPolicy<E> for NotPolicy<E>

Source§

impl<E: Send + Sync + 'static> DomainPolicy<E> for PermitAllPolicy<E>