Skip to main content

Deadline

Struct Deadline 

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

When work must stop. Cloning shares the flag: a host keeps one clone to raise and hands the other to Limits.

use pdfrum_common::Deadline;

// The mechanism: a flag raised from anywhere, on every target.
let stop = Deadline::manual();
let limit = stop.clone();
assert!(!limit.passed());
stop.stop();
assert!(limit.passed());
use std::time::Duration;
use pdfrum_common::Deadline;

// The convenience, where there is a clock: a budget from now.
let deadline = Deadline::after(Duration::from_secs(5));
assert!(!deadline.passed());
assert_eq!(deadline.budget(), Some(Duration::from_secs(5)));

// A zero budget has passed before it is asked.
assert!(Deadline::after(Duration::ZERO).passed());

Implementations§

Source§

impl Deadline

Source

pub fn manual() -> Deadline

A deadline nothing but Deadline::stop raises.

Source

pub fn after(budget: Duration) -> Deadline

Available on non-WebAssembly only.

A deadline budget from now. It can still be raised early with Deadline::stop.

Not available on wasm32, which has no monotonic clock to read: a host there uses Deadline::manual and its own timer.

Source

pub fn with_budget(&self, budget: Duration) -> Deadline

Available on non-WebAssembly only.

This deadline’s flag, with a budget of budget from now.

The returned deadline shares the flag, so Deadline::stop on either raises both — it is the same deadline with a clock added, not a second one beside it. That is what a host wants when it holds a cancel flag and a wall-clock budget: one deadline that answers to whichever arrives first. Building the two separately gives the engine only one of them, because Limits::deadline is a single slot.

An existing budget is replaced, not intersected.

Not available on wasm32, as Deadline::after.

use std::time::Duration;
use pdfrum_common::Deadline;

let flag = Deadline::manual();
let limit = flag.with_budget(Duration::from_secs(30));

// The budget is live on the copy the engine holds...
assert_eq!(limit.budget(), Some(Duration::from_secs(30)));
assert!(!limit.passed());

// ...and the flag still reaches it.
flag.stop();
assert!(limit.passed());
Source

pub fn at(instant: Instant) -> Deadline

Available on non-WebAssembly only.

The deadline at instant; one already in the past has passed.

Not available on wasm32, as Deadline::after.

Source

pub fn stop(&self)

Raises the flag: every check from now on, on every clone, answers that the deadline has passed. Idempotent, and callable from any thread.

Source

pub fn budget(&self) -> Option<Duration>

How much time was allowed, for a deadline made with a budget.

Source

pub fn passed(&self) -> bool

Whether the flag is raised or the budget spent. One atomic load, and a clock read only while the flag is down and a budget is set.

Source

pub fn check(&self, during: Operation) -> Result<(), LimitExceeded>

Ok while the budget lasts and the flag is down; past either, the error that names what was being done. The page, when there is one, is the caller’s to add with LimitExceeded::on_page.

§Errors

LimitExceeded::Stopped once Deadline::stop was called, LimitExceeded::Time once a budget is spent.

Trait Implementations§

Source§

impl Clone for Deadline

Source§

fn clone(&self) -> Deadline

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 Deadline

Source§

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

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

impl Eq for Deadline

Source§

impl PartialEq for Deadline

Two deadlines are equal when they share a flag — clones of one another — which is the question a caller comparing two Limits is asking.

Source§

fn eq(&self, other: &Deadline) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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> 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> 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.