Skip to main content

behavior_actors/atomic/
activation.rs

1//! Capacity for unresolved worker activation authorizations.
2
3use super::capacity::{PositiveCapacity, ZeroCapacity};
4
5/// Positive maximum for unresolved worker activation authorizations.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub struct ActivationPolicy {
8    maximum: PositiveCapacity,
9}
10
11impl ActivationPolicy {
12    /// Select the maximum number of unresolved activation authorizations.
13    ///
14    /// # Errors
15    ///
16    /// Returns [`ZeroCapacity`] when `maximum` is zero.
17    pub fn new(maximum: usize) -> Result<Self, ZeroCapacity> {
18        PositiveCapacity::new(maximum).map(|maximum| Self { maximum })
19    }
20
21    pub(crate) const fn maximum(self) -> usize {
22        self.maximum.get()
23    }
24}
25
26/// Positive maximum number of entries retained by a dynamic supervisor.
27#[derive(Clone, Copy, Debug, Eq, PartialEq)]
28pub struct EntryCapacity {
29    maximum: PositiveCapacity,
30}
31
32impl EntryCapacity {
33    /// Validate a dynamic-supervisor entry capacity.
34    ///
35    /// # Errors
36    ///
37    /// Returns [`ZeroCapacity`] when `maximum` is zero.
38    pub fn new(maximum: usize) -> Result<Self, ZeroCapacity> {
39        PositiveCapacity::new(maximum).map(|maximum| Self { maximum })
40    }
41
42    pub(crate) const fn maximum(self) -> usize {
43        self.maximum.get()
44    }
45}