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
impl IntVectorWriter
Sourcepub fn new<P: AsRef<Path>>(filename: P, width: usize) -> Result<IntVectorWriter>
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.
Sourcepub fn with_buf_len<P: AsRef<Path>>(
filename: P,
width: usize,
buf_len: usize,
) -> Result<IntVectorWriter>
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.
Trait Implementations§
Source§impl Debug for IntVectorWriter
impl Debug for IntVectorWriter
Source§impl Drop for IntVectorWriter
impl Drop for IntVectorWriter
Source§impl Extend<u16> for IntVectorWriter
impl Extend<u16> for IntVectorWriter
Source§fn extend<I: IntoIterator<Item = u16>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = u16>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<u32> for IntVectorWriter
impl Extend<u32> for IntVectorWriter
Source§fn extend<I: IntoIterator<Item = u32>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = u32>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<u64> for IntVectorWriter
impl Extend<u64> for IntVectorWriter
Source§fn extend<I: IntoIterator<Item = u64>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = u64>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<u8> for IntVectorWriter
impl Extend<u8> for IntVectorWriter
Source§fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<usize> for IntVectorWriter
impl Extend<usize> for IntVectorWriter
Source§fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = usize>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)