Skip to main content

Work

Trait Work 

Source
pub trait Work: Clone + Sealed {
    type Retained: Debug;

    // Required methods
    fn retain_storage(&self) -> Self::Retained;
    fn into_storage_owner(self, retained: Self::Retained) -> Memory;
    fn with_storage_owner(&self, memory: Memory) -> (Self, Self::Retained);
    fn memory(&self) -> &Memory;
    fn charge_work(&self, amount: u64) -> Result<(), MemoryError>;

    // Provided methods
    fn vector<T>(&self) -> OwnedVec<T, Self> { ... }
    fn map<K: HashWork, V>(&self) -> OwnedMap<K, V, Self> { ... }
}
Expand description

An execution domain used by accounted collections and schema processing.

Memory owns an independent aggregate domain. Execution additionally borrows a parser’s cumulative ceiling. The sealed implementations ensure that allocator and collection admission cannot bypass either boundary.

Required Associated Types§

Source

type Retained: Debug

Storage ownership retained by the allocator independently of borrowed work.

Required Methods§

Source

fn retain_storage(&self) -> Self::Retained

Keeps an allocation’s account alive even if its collection is forgotten. Owned Memory already holds that account; borrowed Execution supplies one owning handle per collection without allocating a new account.

Source

fn into_storage_owner(self, retained: Self::Retained) -> Memory

Moves the existing account owner when finishing independently owned storage. The sealed implementations preserve the account without cloning it.

Source

fn with_storage_owner(&self, memory: Memory) -> (Self, Self::Retained)

Attaches current work while moving an existing same-account owner. The caller verifies account identity before transferring storage.

Source

fn memory(&self) -> &Memory

The account retaining allocated capacity.

Source

fn charge_work(&self, amount: u64) -> Result<(), MemoryError>

Admits work before execution, against every applicable ceiling.

Provided Methods§

Source

fn vector<T>(&self) -> OwnedVec<T, Self>

Creates empty accounted scratch retaining this execution boundary.

No allocation occurs until a fallible growth operation. A collection borrowing Execution cannot outlive that parser or execution account.

§Examples
use std::sync::Arc;
use structured_asn1::{Parser, memory::{Memory, MemoryAccount, Work}};
let parser = Parser::ber(Memory::new(Arc::new(MemoryAccount::new(1024, 1024))));
let reader = parser.read(&[], 0).unwrap();
let mut scratch = reader.execution().vector();
scratch.try_push(42_u8)?;
assert_eq!(&*scratch, &[42]);
Source

fn map<K: HashWork, V>(&self) -> OwnedMap<K, V, Self>

Creates a bounded scratch map in this storage and execution domain. Hash/probes, table growth and value movement retain the same ceilings.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§