Struct swapvec::SwapVec

source ·
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,

source

pub fn with_config(config: SwapVecConfig) -> Self

Intialize with non-default configuration.

source

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).

source

pub fn push(&mut self, element: T) -> Result<(), SwapVecError>

Push a single element
Might return an error, due to possibly triggered batch flush (IO).

source

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

source

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.

source

pub fn batches_written(&self) -> usize

Basically elements pushed // batch_size

Trait Implementations§

source§

impl<T: Serialize + for<'a> Deserialize<'a>> Debug for SwapVec<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Serialize + for<'a> Deserialize<'a>> Default for SwapVec<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: Serialize + for<'a> Deserialize<'a> + Hash> IntoIterator for SwapVec<T>

§

type Item = Result<T, SwapVecError>

The type of the elements being iterated over.
§

type IntoIter = SwapVecIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for SwapVec<T>where T: RefUnwindSafe,

§

impl<T> Send for SwapVec<T>where T: Send,

§

impl<T> Sync for SwapVec<T>where T: Sync,

§

impl<T> Unpin for SwapVec<T>where T: Unpin,

§

impl<T> UnwindSafe for SwapVec<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.