pub unsafe trait Sink {
// Required methods
fn len(&self) -> usize;
fn capacity(&self) -> usize;
fn grow(&mut self, capacity: usize) -> bool;
fn as_mut_ptr(&mut self) -> *mut u8;
unsafe fn set_len(&mut self, len: usize);
// Provided methods
fn is_empty(&self) -> bool { ... }
fn reserve(&mut self, capacity: usize) -> bool { ... }
fn allocator(&self) -> Option<Allocator> { ... }
}Expand description
A growable byte buffer an algorithm writes its output into, in place.
Vec<u8> is one. A caller with its own string type implements it so the output is written
once, where it ends up: the PHP extension writes straight into a PHP string, which a Vec
would cost a second copy of (and twice the memory, for a moment).
The *_into methods of each algorithm (Gzip::compress_into,
…) append to the sink; Algorithm::compress is
compress_into a new Vec. On an error, what the sink holds is unspecified.
§Safety
Sink::as_mut_ptr points to Sink::capacity writable bytes, the first Sink::len of
them the output so far; Sink::grow and Sink::reserve keep those bytes (the pointer
may change).
Required Methods§
Sourcefn grow(&mut self, capacity: usize) -> bool
fn grow(&mut self, capacity: usize) -> bool
Makes room for capacity bytes in all (nothing to do when there is). false when the
memory is not there, which the algorithm reports as its codec would. The algorithms ask
for what PHP’s function would have at that point, so a sink that grows to exactly that
(reallocating in place, as PHP’s allocator does for a large block) holds no more.
Sourcefn as_mut_ptr(&mut self) -> *mut u8
fn as_mut_ptr(&mut self) -> *mut u8
The start of the buffer.
Provided Methods§
Sourcefn reserve(&mut self, capacity: usize) -> bool
fn reserve(&mut self, capacity: usize) -> bool
Sink::grow to capacity when that is cheap to do: a guess at the final size (a gzip
trailer’s length, a bound) that saves growing step by step. Declining (false) is
never an error; the algorithm then grows as it needs to.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".