Skip to content

Commit

Permalink
Added into_inner
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jul 4, 2022
1 parent 7be3cd6 commit 49b545e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/write/compression.rs
Expand Up @@ -107,11 +107,6 @@ pub struct Compressor<I: Iterator<Item = Result<EncodedPage>>> {
}

impl<I: Iterator<Item = Result<EncodedPage>>> Compressor<I> {
/// Creates a new [`Compressor`]
pub fn new_from_vec(iter: I, compression: CompressionOptions, buffer: Vec<u8>) -> Self {
Self::new(iter, compression, buffer)
}

/// Creates a new [`Compressor`]
pub fn new(iter: I, compression: CompressionOptions, buffer: Vec<u8>) -> Self {
Self {
Expand All @@ -121,6 +116,22 @@ impl<I: Iterator<Item = Result<EncodedPage>>> Compressor<I> {
current: None,
}
}

/// Creates a new [`Compressor`] (same as `new`)
pub fn new_from_vec(iter: I, compression: CompressionOptions, buffer: Vec<u8>) -> Self {
Self::new(iter, compression, buffer)
}

/// Deconstructs itself into its iterator and scratch buffer.
pub fn into_inner(mut self) -> (I, Vec<u8>) {
let mut buffer = if let Some(page) = self.current.as_mut() {
std::mem::take(page.buffer())
} else {
std::mem::take(&mut self.buffer)
};
buffer.clear();
(self.iter, buffer)
}
}

impl<I: Iterator<Item = Result<EncodedPage>>> FallibleStreamingIterator for Compressor<I> {
Expand Down

0 comments on commit 49b545e

Please sign in to comment.