pub trait Scratch {
type Error: Debug;
// Required methods
fn write(&mut self, bytes: &[u8]) -> Result<(), Self::Error>;
fn len(&self) -> u64;
fn freeze(&mut self) -> Result<&[u8], Self::Error>;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
An append-only staging area: build it sequentially with
write, then freeze it into a
readable byte view for random and sequential reads. Dropping it discards the
storage.
It is the write-side sibling of Storage: no_std core owns an algorithm
that needs to spill more bytes than fit in RAM and read them back, and the
host injects the actual backing — typically a temp file that is memory-mapped
on freeze (see plugmem-host’s FileScratch). The reference
MemScratch backs tests with a plain in-RAM buffer.
§Contract
writeappends; call it any number of times, in the order the bytes should land.freezeends the build and returns all written bytes as one contiguous slice; the borrow keeps the region readable. Nowriteafter afreeze.- What
freezehands back must equal the concatenation of everywrite.
plugmem uses it for the disk-first maintain/recover rebuild, which streams
the large pools (vectors, text) through a Scratch instead of holding them
in RAM — but the trait itself knows nothing of that.
Required Associated Types§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".