pub struct BandwidthGovernor { /* private fields */ }Expand description
Applies BandwidthPolicy through auto-governors for battery, metered
connections, and disk-budget pressure.
use xlb::{BandwidthGovernor, BandwidthPolicy, BwCaps, PeerTier};
let g = BandwidthGovernor::new(
BandwidthPolicy::default()
.role(PeerTier::Workstation, BwCaps { up_mbit: 5, down_mbit: 50 }),
);
// AC power: returns configured caps.
assert_eq!(g.effective_caps(PeerTier::Workstation).up_mbit, 5);
// Battery: drops to passive.
g.set_battery(true);
assert_eq!(g.effective_caps(PeerTier::Workstation).up_mbit, 0);Implementations§
Source§impl BandwidthGovernor
impl BandwidthGovernor
Sourcepub fn new(policy: BandwidthPolicy) -> Self
pub fn new(policy: BandwidthPolicy) -> Self
Create a governor wrapping policy. Starts in AC / unmetered mode.
Sourcepub fn effective_caps(&self, tier: PeerTier) -> BwCaps
pub fn effective_caps(&self, tier: PeerTier) -> BwCaps
Return effective BwCaps for tier.
Returns BwCaps::passive() when on battery or a metered connection;
otherwise delegates to the configured BandwidthPolicy.
Sourcepub fn is_passive(&self) -> bool
pub fn is_passive(&self) -> bool
true when any governor is forcing passive mode.
Sourcepub fn is_on_battery(&self) -> bool
pub fn is_on_battery(&self) -> bool
true when the battery governor has flagged on-battery power.
Sourcepub fn is_metered(&self) -> bool
pub fn is_metered(&self) -> bool
true when the metered-connection governor is active.
Sourcepub fn set_battery(&self, on_battery: bool)
pub fn set_battery(&self, on_battery: bool)
Override battery state (for testing or OS-event callbacks).
Sourcepub fn set_metered(&self, metered: bool)
pub fn set_metered(&self, metered: bool)
Override metered-connection state (for testing or OS-event callbacks).
Sourcepub fn probe_os(&self)
pub fn probe_os(&self)
Probe the OS for power-source state and update the governor.
Failure is silently ignored — a detection error leaves the governor in its current state. Call this at startup and on relevant OS events.
Sourcepub fn has_policy(&self) -> bool
pub fn has_policy(&self) -> bool
True if the configured policy has any non-passive entries.
Trait Implementations§
Source§impl Clone for BandwidthGovernor
impl Clone for BandwidthGovernor
Source§fn clone(&self) -> BandwidthGovernor
fn clone(&self) -> BandwidthGovernor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BandwidthGovernor
impl RefUnwindSafe for BandwidthGovernor
impl Send for BandwidthGovernor
impl Sync for BandwidthGovernor
impl Unpin for BandwidthGovernor
impl UnsafeUnpin for BandwidthGovernor
impl UnwindSafe for BandwidthGovernor
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more