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
impl Workspace
Sourcepub fn new(limits: Limits) -> Self
pub fn new(limits: Limits) -> Self
Create an empty workspace with explicit limits.
Examples found in repository?
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}Sourcepub fn set_retention(&mut self, retention: Retention)
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.
Sourcepub fn set_limits(&mut self, limits: Limits)
pub fn set_limits(&mut self, limits: Limits)
Set limits and release scratch so a lower budget is effective immediately.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Workspace
impl RefUnwindSafe for Workspace
impl Send for Workspace
impl Sync for Workspace
impl Unpin for Workspace
impl UnsafeUnpin for Workspace
impl UnwindSafe for Workspace
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
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