Skip to main content

ReloadablePolicy

Struct ReloadablePolicy 

Source
pub struct ReloadablePolicy { /* private fields */ }
Expand description

A hot-reloadable Policy holder for the enforcement point: the active policy can be swapped at runtime (e.g. when the policy file changes) without a restart, while readers keep the coarse evaluate path lock-light.

It wraps an Arc<Policy> behind an RwLock. Per request the guard calls current — a brief read-lock returning a cheap Arc clone it then evaluates against; a reload calls store — a brief write-lock swapping the Arc. A request in flight during a reload finishes against the snapshot it took, so a swap is never observed mid-evaluation. Poison-safe: a panic elsewhere never makes current/store panic (verifier rule: no panics in the API).

The trigger (a file-mtime watch, a signal, an admin endpoint) is the service’s concern — this type only holds and swaps the value.

Implementations§

Source§

impl ReloadablePolicy

Source

pub fn new(policy: Policy) -> Self

Wrap an initial policy (e.g. the one loaded at boot).

Source

pub fn current(&self) -> Arc<Policy> ⓘ

The currently active policy — a cheap Arc clone taken under a brief read-lock. Evaluate against the returned snapshot; a concurrent store does not affect it.

Source

pub fn store(&self, policy: Policy)

Atomically replace the active policy (a brief write-lock). New requests see the new policy; in-flight requests finish against the snapshot they already took.

Trait Implementations§

Source§

impl Debug for ReloadablePolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.