pub struct RawVectorWriter { /* private fields */ }Expand description
A buffered file writer compatible with the serialization format of RawVector.
When the writer goes out of scope, the internal buffer is flushed, the file is closed, and all errors are ignored.
Call RawVectorWriter::close explicitly to handle the errors.
§Examples
use simple_sds_sbwt::raw_vector::{RawVector, RawVectorWriter, AccessRaw, PushRaw};
use simple_sds_sbwt::serialize;
use std::fs;
let filename = serialize::temp_file_name("raw-vector-writer");
let width = 29;
let mut header: Vec<u64> = Vec::new();
let mut writer = RawVectorWriter::new(&filename, &mut header).unwrap();
unsafe {
writer.push_int(123, width);
writer.push_int(456, width);
writer.push_int(789, width);
}
writer.close();
let v: RawVector = serialize::load_from(&filename).unwrap();
assert_eq!(v.len(), 3 * width);
unsafe {
assert_eq!(v.int(0, width), 123);
assert_eq!(v.int(width, width), 456);
assert_eq!(v.int(2 * width, width), 789);
}
fs::remove_file(&filename);Implementations§
Source§impl RawVectorWriter
impl RawVectorWriter
Sourcepub const DEFAULT_BUFFER_SIZE: usize = 8_388_608usize
pub const DEFAULT_BUFFER_SIZE: usize = 8_388_608usize
Default buffer size in bits.
Sourcepub fn new<P: AsRef<Path>>(
filename: P,
header: &mut Vec<u64>,
) -> Result<RawVectorWriter>
pub fn new<P: AsRef<Path>>( filename: P, header: &mut Vec<u64>, ) -> Result<RawVectorWriter>
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.header: Header of the parent structure (may be empty).
Sourcepub fn with_buf_len<P: AsRef<Path>>(
filename: P,
header: &mut Vec<u64>,
buf_len: usize,
) -> Result<RawVectorWriter>
pub fn with_buf_len<P: AsRef<Path>>( filename: P, header: &mut Vec<u64>, buf_len: usize, ) -> Result<RawVectorWriter>
Creates an empty vector stored in the specified file with user-defined buffer size.
If the file already exists, it will be overwritten.
The buffer size will be rounded up to the next multiple of bits::WORD_BITS.
§Arguments
filename: Name of the file.header: Header of the parent structure (may be empty).buf_len: Buffer size in bits.
Trait Implementations§
Source§impl Debug for RawVectorWriter
impl Debug for RawVectorWriter
Source§impl Drop for RawVectorWriter
impl Drop for RawVectorWriter
Auto Trait Implementations§
impl Freeze for RawVectorWriter
impl RefUnwindSafe for RawVectorWriter
impl Send for RawVectorWriter
impl Sync for RawVectorWriter
impl Unpin for RawVectorWriter
impl UnwindSafe for RawVectorWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more