Skip to main content

Policy

Trait Policy 

Source
pub(crate) trait Policy {
    // Required methods
    fn is_blocking(&self) -> bool;
    fn take_one(&mut self) -> Result<(), Bug>;
}
Expand description

A policy that describes whether cells can be sent on a SinkBlocker.

Each Policy object can be in different states: some states cause the SinkBlocker to block traffic, and some cause the SinkBlocker to permit traffic.

The user of a SinkBlocker is expected to call update_policy() from time to time, when they need to make a manual change in the SinkBlocker’s status. This is the only way for a blocked SinkBlocker to become unblocked.

Invariants:

  • The state of a Policy object may transition from non-blocking to blocking.
  • The state of a Policy object may not transition from blocking to non-blocking.
  • If is_blocking() has returned false, and no intervening changes have been made to the Policy, take_one() will succeed.

Note that because of this last invariant, interior mutability is strongly discouraged for implementations of this trait.

Required Methods§

Source

fn is_blocking(&self) -> bool

Returns true if this policy is currently blocking.

Invariant: If this returns true on a given Policy, it must always return true on that Policy in the future. (That is, a Policy may become blocked, but may not become unblocked.)

Source

fn take_one(&mut self) -> Result<(), Bug>

Modify this policy in response to having queued one item.

Requires that self.is_blocking() has just returned false. Returns an error, and does not change self, if this is blocked. (That is, you must only call this function on a non-blocked Policy.)

Implementors§