IntVectorWriter

Struct IntVectorWriter 

Source
pub struct IntVectorWriter { /* private fields */ }
Expand description

A buffered file writer compatible with the serialization format of IntVector.

When the writer goes out of scope, the internal buffer is flushed, the file is closed, and all errors are ignored. Call IntVectorWriter::close explicitly to handle the errors.

§Examples

use simple_sds_sbwt::int_vector::{IntVector, IntVectorWriter};
use simple_sds_sbwt::ops::{Vector, Access, Push};
use simple_sds_sbwt::serialize;
use std::fs;

let filename = serialize::temp_file_name("int-vector-writer");
let mut writer = IntVectorWriter::new(&filename, 13).unwrap();
assert!(writer.is_empty());
writer.push(123); writer.push(456); writer.push(789);
assert_eq!(writer.len(), 3);
writer.close().unwrap();

let v: IntVector = serialize::load_from(&filename).unwrap();
assert_eq!(v.len(), 3);
assert_eq!(v.get(0), 123); assert_eq!(v.get(1), 456); assert_eq!(v.get(2), 789);
fs::remove_file(&filename).unwrap();

Implementations§

Source§

impl IntVectorWriter

Source

pub fn new<P: AsRef<Path>>(filename: P, width: usize) -> Result<IntVectorWriter>

Creates an empty vector stored in the specified file with the default buffer size.

If the file already exists, it will be overwritten.

§Arguments
  • filename: Name of the file.
  • width: Width of each item in bits.
§Errors

Returns an error of the kind ErrorKind::Other if the width is invalid. Any I/O errors will be passed through.

Source

pub fn with_buf_len<P: AsRef<Path>>( filename: P, width: usize, buf_len: usize, ) -> Result<IntVectorWriter>

Creates an empty vector stored in the specified file with user-defined buffer size.

If the file already exists, it will be overwritten. Actual buffer size may be slightly higher than requested.

§Arguments
  • filename: Name of the file.
  • width: Width of each item in bits.
  • buf_len: Buffer size in items.
§Errors

Returns an error of the kind ErrorKind::Other if the width is invalid. Any I/O errors will be passed through.

§Panics

May panic if buffer length would exceed the maximum length.

Source

pub fn filename(&self) -> &Path

Returns the name of the file.

Source

pub fn is_open(&self) -> bool

Returns true if the file is open for writing.

Source

pub fn close(&mut self) -> Result<()>

Flushes the buffer, writes the header, and closes the file.

No effect if the file is closed.

§Errors

Any I/O errors will be passed through.

Trait Implementations§

Source§

impl Debug for IntVectorWriter

Source§

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

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

impl Drop for IntVectorWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Extend<u16> for IntVectorWriter

Source§

fn extend<I: IntoIterator<Item = u16>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<u32> for IntVectorWriter

Source§

fn extend<I: IntoIterator<Item = u32>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<u64> for IntVectorWriter

Source§

fn extend<I: IntoIterator<Item = u64>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<u8> for IntVectorWriter

Source§

fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<usize> for IntVectorWriter

Source§

fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Push for IntVectorWriter

Source§

fn push(&mut self, value: <Self as Vector>::Item)

Appends an item to the vector. Read more
Source§

impl Vector for IntVectorWriter

Source§

type Item = u64

The type of the items in the vector.
Source§

fn len(&self) -> usize

Returns the number of items in the vector.
Source§

fn width(&self) -> usize

Returns the width of of an item in bits.
Source§

fn max_len(&self) -> usize

Returns the maximum length of the vector.
Source§

fn is_empty(&self) -> bool

Returns true if the vector is empty.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.