use bytes::Bytes;
pub struct RowChunk {
rows: Vec<Bytes>,
}
impl RowChunk {
#[must_use]
pub const fn new() -> Self {
Self { rows: Vec::new() }
}
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
Self {
rows: Vec::with_capacity(capacity),
}
}
pub fn push(&mut self, row: Bytes) {
self.rows.push(row);
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.rows.is_empty()
}
#[must_use]
pub const fn len(&self) -> usize {
self.rows.len()
}
#[must_use]
pub fn into_rows(self) -> Vec<Bytes> {
self.rows
}
}
impl Default for RowChunk {
fn default() -> Self {
Self::new()
}
}
pub struct ChunkingStrategy {
chunk_size: usize,
}
impl ChunkingStrategy {
#[must_use]
pub const fn new(chunk_size: usize) -> Self {
Self { chunk_size }
}
#[must_use]
pub const fn is_full(&self, chunk: &RowChunk) -> bool {
chunk.len() >= self.chunk_size
}
#[must_use]
pub fn new_chunk(&self) -> RowChunk {
RowChunk::with_capacity(self.chunk_size)
}
}
impl Default for ChunkingStrategy {
fn default() -> Self {
Self::new(256)
}
}
#[cfg(test)]
mod tests;