Skip to main content

Destination

Trait Destination 

Source
pub trait Destination: Send {
    // Required methods
    fn as_mut_slice(&mut self) -> &mut [u8] ⓘ;
    fn freeze(self) -> Bytes;
}
Expand description

One buffer’s worth of memory, filled by a driver and then handed to the caller.

Implement this alongside DestinationAlloc to make reads land in memory your runtime owns. The address MUST NOT move between as_mut_slice calls: a driver may hold a pointer into it across a suspension (ADR-041 § 6a).

§Examples

use bytes::Bytes;
use hurray_io::stream::Destination;

/// A destination that ignores alignment — fine for a test, not for a reader.
struct VecDest(Vec<u8>);

impl Destination for VecDest {
    fn as_mut_slice(&mut self) -> &mut [u8] {
        &mut self.0
    }
    fn freeze(self) -> Bytes {
        Bytes::from(self.0)
    }
}

let mut dest = VecDest(vec![0u8; 4]);
dest.as_mut_slice().copy_from_slice(b"hurr");
assert_eq!(dest.freeze(), Bytes::from_static(b"hurr"));

Required Methods§

Source

fn as_mut_slice(&mut self) -> &mut [u8] ⓘ

The bytes to fill, exactly byte_size long.

Source

fn freeze(self) -> Bytes

Hands the filled memory out as [Bytes], without copying it.

Takes self by value rather than Box<Self>: the core names this type through DestinationAlloc::Dest, so a destination is never boxed and never erased.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§