pub struct Budget { /* private fields */ }Expand description
Time budget in the tropical semiring (min, +).
Budget decreases additively via consume and the
constraint propagates as the minimum of parent and child budgets.
use franken_kernel::Budget;
let b = Budget::new(1000);
let b2 = b.consume(300).unwrap();
assert_eq!(b2.remaining_ms(), 700);
assert!(b2.consume(800).is_none()); // would exceed budgetImplementations§
Source§impl Budget
impl Budget
Sourcepub const fn remaining_ms(self) -> u64
pub const fn remaining_ms(self) -> u64
Milliseconds remaining.
Sourcepub const fn consume(self, ms: u64) -> Option<Self>
pub const fn consume(self, ms: u64) -> Option<Self>
Consume ms milliseconds from the budget.
Returns None if insufficient budget remains.
Sourcepub const fn is_exhausted(self) -> bool
pub const fn is_exhausted(self) -> bool
Whether the budget is fully exhausted.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Budget
impl<'de> Deserialize<'de> for Budget
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Budget
impl Ord for Budget
Source§impl PartialOrd for Budget
impl PartialOrd for Budget
impl Copy for Budget
impl Eq for Budget
impl StructuralPartialEq for Budget
Auto Trait Implementations§
impl Freeze for Budget
impl RefUnwindSafe for Budget
impl Send for Budget
impl Sync for Budget
impl Unpin for Budget
impl UnsafeUnpin for Budget
impl UnwindSafe for Budget
Blanket Implementations§
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
Mutably borrows from an owned value. Read more