pub struct SwapVec<T>where
for<'a> T: Serialize + Deserialize<'a>,{ /* private fields */ }Expand description
An only growing array type which swaps to disk, based on it’s initial configuration.
Create a mutable instance, and then pass iterators or elements to grow it.
let mut bigvec = swapvec::SwapVec::default();
let iterator = (0..9);
bigvec.consume(iterator);
bigvec.push(99);
let new_iterator = bigvec.into_iter();Implementations§
source§impl<T> SwapVec<T>where
for<'a> T: Serialize + Deserialize<'a> + Hash,
impl<T> SwapVec<T>where for<'a> T: Serialize + Deserialize<'a> + Hash,
sourcepub fn with_config(config: SwapVecConfig) -> Self
pub fn with_config(config: SwapVecConfig) -> Self
Intialize with non-default configuration.
sourcepub fn consume(
&mut self,
it: impl Iterator<Item = T>
) -> Result<(), SwapVecError>
pub fn consume( &mut self, it: impl Iterator<Item = T> ) -> Result<(), SwapVecError>
Give away an entire iterator for consumption.
Might return an error, due to possibly triggered batch flush (IO).
sourcepub fn push(&mut self, element: T) -> Result<(), SwapVecError>
pub fn push(&mut self, element: T) -> Result<(), SwapVecError>
Push a single element
Might return an error, due to possibly triggered batch flush (IO).
sourcepub fn written_to_file(&self) -> bool
pub fn written_to_file(&self) -> bool
Check if a file has been created.
Is false if element count is below swap_after and below batch_size
sourcepub fn file_size(&self) -> Option<Result<u64, SwapVecError>>
pub fn file_size(&self) -> Option<Result<u64, SwapVecError>>
Get the file size in bytes of the temporary file. Might do IO and therefore could return some Result.
sourcepub fn batches_written(&self) -> usize
pub fn batches_written(&self) -> usize
Basically elements pushed // batch_size