RawVectorWriter

Struct RawVectorWriter 

Source
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

Source

pub const DEFAULT_BUFFER_SIZE: usize = 8_388_608usize

Default buffer size in bits.

Source

pub fn len(&self) -> usize

Returns the length of the vector in bits.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector is empty.

Source

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

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

Source

pub fn close_with_header(&mut self, header: &mut Vec<u64>) -> Result<()>

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

No effect if the file is closed. This method should only be called by the close method of a parent writer.

§Errors

Any I/O errors will be passed through.

Trait Implementations§

Source§

impl Debug for RawVectorWriter

Source§

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

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

impl Drop for RawVectorWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PushRaw for RawVectorWriter

Source§

fn push_bit(&mut self, value: bool)

Appends a bit to the container. Read more
Source§

unsafe fn push_int(&mut self, value: u64, width: usize)

Appends an integer to the container. Read more

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.