Skip to main content

ChunkRecord

Trait ChunkRecord 

Source
pub trait ChunkRecord {
    type Key;
    type Part;

    // Required method
    fn into_chunk(self) -> (Self::Key, ChunkPosition, Self::Part);
}
Expand description

A wire record that is one chunk of a run: it names the message it is part of (its key, such as a batch number), its position in the run, and carries its part of the message’s items.

Protocol crates implement this for each chunked record they define, so a handler passes the record it was called with straight to the driver’s ChunkRunAssembler::push_record. It lives here so a protocol crate needs no transport dependency to implement it.

use rpc_api::{ChunkPosition, ChunkRecord};

// The shape a chunked wire record takes: the message it belongs to, its
// position in the run, and its slice of the items.
struct UpdateChunk {
    batch: i64,
    chunk_index: u32,
    chunk_count: u32,
    updates: Vec<i64>,
}

impl ChunkRecord for UpdateChunk {
    type Key = i64;
    type Part = Vec<i64>;

    fn into_chunk(self) -> (i64, ChunkPosition, Vec<i64>) {
        let position = ChunkPosition::new(self.chunk_index, self.chunk_count);
        (self.batch, position, self.updates)
    }
}

let chunk = UpdateChunk { batch: 7, chunk_index: 1, chunk_count: 2, updates: vec![3] };
assert_eq!(chunk.into_chunk(), (7, ChunkPosition::new(1, 2), vec![3]));

Required Associated Types§

Source

type Key

Identifies the message the run carries.

Source

type Part

One chunk’s payload.

Required Methods§

Source

fn into_chunk(self) -> (Self::Key, ChunkPosition, Self::Part)

Takes the record apart into its key, its position and its part.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§