Skip to main content

Budget

Struct Budget 

Source
pub struct Budget {
    pub time: Option<Duration>,
    pub memory: Option<u64>,
    /* private fields */
}
Expand description

A run’s time and memory limits, and once armed, the flag that says whether either is exhausted (see the module documentation).

Fields§

§time: Option<Duration>

The wall-clock limit; None is unlimited. TLC setting: None.

§memory: Option<u64>

The whole-process resident-memory ceiling, in bytes; None is unlimited. TLC setting: its JVM heap (default_memory).

Implementations§

Source§

impl Budget

Source

pub const fn unlimited() -> Self

No limit at all.

Source

pub const fn new(time: Option<Duration>, memory: Option<u64>) -> Self

time and memory, not yet armed.

Source

pub const fn is_unlimited(&self) -> bool

Whether neither limit is set.

Source

pub const fn is_armed(&self) -> bool

Whether this budget is armed, by Self::start or by a caller that already started its watchdog.

Source

pub fn start(&self) -> Result<Option<Watchdog>, StartError>

Arms the budget: starts the watchdog thread and returns it. The watchdog stops when dropped. None means unlimited or already armed.

§Errors

Returns StartError when the initial memory observation is unavailable or the thread cannot start. Callers must abort rather than disable limits.

Source

pub fn poll(&self) -> Result<Option<Exhausted>, MeasurementError>

What is exhausted, if anything. One relaxed load while the budget holds; Ok(None) for an unarmed budget.

§Errors

Returns the first unavailable process-memory observation. It is never converted into a resource exhaustion with an invented byte count.

Source

pub fn memory_samples(&self) -> Option<MemorySamples>

Actual memory samples of this armed run, if it has been started.

Trait Implementations§

Source§

impl Clone for Budget

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Budget

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Budget

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for Budget

§

impl Freeze for Budget

§

impl Move 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.