Skip to main content

Workspace

Struct Workspace 

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

Reusable fallibly allocated scratch storage and per-call resource limits.

Cache work counts topology/index validation, each adjacency initialization, insertion, search and score update, and each cache/emission visit. Overdraw work counts validation, cache simulation, geometry and counting-sort record visits, and copied indices. Fixed scalar arithmetic inside a visit is not counted separately. Simplification counts validation, position/hash and adjacency visits, edge searches, classification, quadric and attribute accumulation, collapse ranking/sorting/flip checks, and remapping visits. Its typed scratch is allocated fallibly and retained after successful calls; retained scratch is reused when it fits and released under limit pressure, including excess capacity in buffers the current call uses. Use Self::set_retention to opt into Retention::Lean. Usage reports peak storage including all retained workspace buffers. Scale computation is allocation-free and has no workspace argument. Limits never disable checked size arithmetic.

Implementations§

Source§

impl Workspace

Source

pub fn new(limits: Limits) -> Self

Create an empty workspace with explicit limits.

Examples found in repository?
examples/untrusted_input.rs (line 15)
3fn main() -> Result<(), Error> {
4    // Check transport sizes before buffering a request or creating its views.
5    let source = [0u8; 4]; // Deliberately malformed stream supplied by a client.
6    let count = 3usize;
7    let stride = 12usize;
8    let limits = Limits {
9        max_bytes: 64 << 20,
10        max_work: 1 << 20,
11    };
12    if source.len() > limits.max_bytes || count > limits.max_bytes / stride {
13        return Err(Error::LimitExceeded);
14    }
15    let mut workspace = Workspace::new(limits);
16    match decode_vertex_buffer(count, stride, &source, &mut workspace) {
17        Ok(bytes) => println!("{} decoded bytes", bytes.len()),
18        Err(Error::InvalidStream) => println!("rejected malformed input"),
19        Err(error) => return Err(error),
20    }
21    Ok(())
22}
Source

pub const fn retention(&self) -> Retention

Current scratch retention policy.

Source

pub fn set_retention(&mut self, retention: Retention)

Set the retention policy, releasing scratch and resetting measurements if the policy changes. Limits are preserved; Self::clear and Self::set_limits preserve this policy.

Source

pub const fn limits(&self) -> Limits

Current per-call limits.

Source

pub fn set_limits(&mut self, limits: Limits)

Set limits and release scratch so a lower budget is effective immediately.

Source

pub fn clear(&mut self)

Release all retained scratch allocations and reset measurements.

Source

pub const fn usage(&self) -> Usage

Measurements for the most recent call, including a failed call’s work.

Trait Implementations§

Source§

impl Debug for Workspace

Source§

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

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

impl Default for Workspace

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.