pub trait DestinationAlloc: Send {
type Dest: Destination;
// Required method
fn allocate(&mut self, request: DestinationRequest) -> Result<Self::Dest>;
}Expand description
Allocates the destinations a StreamReaderCore fills.
§Examples
use hurray_io::stream::{Destination, DestinationAlloc, SystemDestinations, DestinationRequest};
let mut alloc = SystemDestinations;
let mut dest = alloc
.allocate(DestinationRequest { index: 0, byte_size: 128, alignment: 4096 })?;
assert_eq!(dest.as_mut_slice().len(), 128);Required Associated Types§
Sourcetype Dest: Destination
type Dest: Destination
The memory this allocator hands out.
An associated type rather than Box<dyn Destination>: the core is generic over the
allocator, so the destination’s concrete type is known throughout. That costs one
type parameter and saves a heap allocation per buffer — and it keeps the core’s
auto traits (Sync, UnwindSafe, RefUnwindSafe) intact, which a trait object
would erase from every type that contains a reader.
Required Methods§
Sourcefn allocate(&mut self, request: DestinationRequest) -> Result<Self::Dest>
fn allocate(&mut self, request: DestinationRequest) -> Result<Self::Dest>
Allocates one destination, zero-initialised, at the requested alignment.
§Errors
Error::UnallocatableBuffer when the request cannot be satisfied — a byte_size
beyond the address space, or an alignment this allocator cannot meet. A
descriptor off the wire can ask for either, so this MUST NOT panic.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".